本文介绍了从twitter api实体参数php获取图片网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过entities参数获取并显示使用php发布的推文中的图像。我在我的网址中有include_entities,可以看到返回的json中的实体。
I'm attempting to get and display images posted in a tweet with php via the entities parameter. I have include_entities in my url and can see the entities in the returned json.
在我的foreach循环中,我正在执行以下操作:
In my foreach loop, I am doing the following:
foreach($results as $result){
$media_url = $result->entities->media->media_url;
$media_size_h = $result->entities->media->sizes->small->h;
$media_size_w = $result->entities->media->sizes->small->w;
...
}
但是,这不会返回任何内容。
However, this is not returning anything.
对于我的输出,我有......
For my output, I have...
if(strlen($media_url) > 0)
{
//format table for tweets with images
} else {
//format table for regular tweets
}
这是json ...
And this is the json...
array(20) {
[0]=>
object(stdClass)#5 (21) {
...
["entities"]=>
object(stdClass)#7 (4) {
["media"]=>
array(1) {
[0]=>
object(stdClass)#8 (10) {
["type"]=>
string(5) "photo"
["media_url"]=>
string(38) "http://photourl.jpg"
...
["sizes"]=>
object(stdClass)#9 (4) {
["thumb"]=>
object(stdClass)#10 (3) {
["resize"]=>
string(4) "crop"
["h"]=>
int(150)
["w"]=>
int(150)
}
...
}
为什么这不起作用的任何想法?任何帮助将非常感激!
Any ideas why this is not working? Any help would be much appreciated!
推荐答案
$ result-> entities-> media->
这是一个在结构中看到的数组...尝试使用
$result->entities->media->
this is an array as seen in structure... try using
$media_url = $result->entities->media[0]->media_url;
这篇关于从twitter api实体参数php获取图片网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!