json - Facebook Graph API get page post's attachments -


i trying url of image attachment published facebook page. goal embed image in webpage in order website display last image attachment published page. own both website , fb page.

i have yet not grasped details on handling facebook graph api, here did far:

1) in fb developers website, have created application, getting app id , secret;

2) used information access token (just pasted in browser following code:

https://graph.facebook.com/oauth/access_token?client_id={my-client-id}&client_secret={my-client-secret}&grant_type=client_credentials 

3) in website, have loaded facebook js sdk after body tag; , got facebook page id facebook page administration;

4) real question begins: how can query facebook information need – source url of last published image?

the best result have gotten far making getjson call of jquery:

var fbfeed = $j.getjson('https://graph.facebook.com/{my-page-id}/feed?access_token={my-token}&fields=attachments&limit=1'); 

this , store json array in fbfeed variable (please correct me if i'm wrong). 1 of keys of array called "src" contains source url of attachment – information need embed picture in website;

i have following problems / concerns: - have not found way retrieve value of "url" key – how can that? how can parse fbfeed variable , extract value of "url" key?

– have concerns usage of access token:

  • is problematic expose access token in way, using in jquery function? security risk? if so, can "mimic" request using server side language such php?

  • will access token expire (i.e. need repeat step 2 time time?). so, imagining can work, need time time "refresh" access token?

thanks help.

i have managed information needed using server-side code, although may not "clean solution": iterate through last 5 posts of page until finds image , post url:

<?php $url = 'https://graph.facebook.com/{page-id}/feed?access_token={access-token}&fields=attachments,link&limit=5'; $json = file_get_contents($url); $json_data = json_decode($json, true);  for($count = 0; $count < 5; $count++) {  $imagesource =  $json_data['data'][$count]['attachments']['data'][0]['media']['image']['src']; // gets image url  $postlink = $json_data['data'][$count]['link']; // gets post url  if (isset($imagesource) && isset($postlink)) {     // stuff image , post url     break;     };  };  // can other stuff fallback if image url , post url not found 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -