Display [Image][url] from Graph API

落爺英雄遲暮 提交于 2019-12-10 22:14:40

问题


Building an Facebook Video application. Users can Favorite videos by using in app og.like.

I use

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

and i will get

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

To get url i use.

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

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

Then

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

The issue is to display the image. If i click the ID in graph API i will get

{
  "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
}

My question is. How do i display the image ?


回答1:


After you get the $Object, make the \GET request to this object-

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

Then fetch the image urls from the response-

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



回答2:


Basically you'll need to make a request with the Object id to get the desired image from Facebook Graph.

So, after you assign $Object = $data['data']['object'] You can simply get the JSON from http://graph.facebook.com/$Object['id'] and to get the image.

Example code:

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

$myImage will be the object image url.

Good Luck, Guy.



来源:https://stackoverflow.com/questions/18078346/display-imageurl-from-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!