从Graph API显示[Image] [url]

时间:2013-08-06 11:00:25

标签: php facebook facebook-graph-api facebook-php-sdk

构建Facebook视频应用程序。用户可以在应用程序og.like中使用收藏的视频。

我用

$response = $facebook->api(
  'me/og.likes',
  'GET'

我会得到

"data": {
    "object": {
      "id": "1399918593560042", 
      "url": "http://some_url.com", 
      "type": "video.tv_show", 
      "title": "the_video_title"
    }

获取我使用的网址。

$response = $facebook->api(
 'me/og.likes?app_id_filter=381977341837631',
 'GET'
);

foreach ( $response['data'] as $data ); 
$Object = $data['data']['object'];

然后

 <li class="program"><a class="thumbnail" data-transition="slide" href="<?php echo $Object['url']; ?>">
  <img src="IMG_URL"></a></li> 

问题是显示图像。如果我点击图API中的ID,我将获得

{
  "id": "1399918593560042", 
  "url": "http://some_url.com", 
  "type": "video.tv_show", 
 "title": "the_video_title", 
  "image": [
{
  "url": "https://v.redli.se/p/102/sp/10200/thumbnail/entry_id/0_53lzx39w/width/1024/height/720", 
  "secure_url": "https://v.redli.se/p/102/sp/10200/thumbnail/entry_id/0_53lzx39w/width/1024/height/720", 
  "type": "image/jpg", 
  "width": 1024, 
  "height": 576
}

我的问题是。我如何显示图像?

2 个答案:

答案 0 :(得分:1)

基本上,您需要使用Object id发出请求,以便从Facebook Graph获取所需的图像。

所以,在你分配$ Object = $ data ['data'] ['object']之后 您只需从http://graph.facebook.com/ $ Object ['id']获取JSON即可 并获得图像。

示例代码:

$facebookJSON = file_get_contents("https://graph.facebook.com/" . $Object['id']);
$myArr = json_decode($facebookJSON, 1);
$myImage = $myArr['image']['url'];

$ myImage将是对象图片网址。

祝你好运, 盖

答案 1 :(得分:1)

获得$Object后,请向此对象发出\GET个请求 -

$resp = $facebook->api($Object['id']);

然后从响应中获取图像URL -

if(isset($resp['image']))
{
   foreach ($resp['image'] as $image) 
   {
       echo $imag_url = $image['url'];
   }
}