How to get an image url from Facebook graph API for a given URL in a single call
<p>I am trying to get the image url data from a shared link in Facebook graph API. I can get this but it seems a very hacky way to do so as it involves a double server call and relies on an old API version and I would much rather a nice clean way to do this with current version of the API - 2.5.</p>

<p>Up until 2.4 I could use the 2.3 API to request the below with the url of the link I am trying to get an image for
<code>https://graph.facebook.com/v2.3/?id=http%3A%2F%2Fwww.google.co.uk&amp;access_token=xxxxx</code></p>

<p>and it would return the same as the 2.5 version of the API:</p>

<pre><code>{
   "og_object": {
      "id": "383886459583",
      "description": "Happy St. David's Day 2016 #GoogleDoodle",
      "title": "Google",
      "type": "website",
      "updated_time": "2016-03-01T10:58:02+0000",
      "url": "http://www.google.co.uk/"
   },
   "share": {
      "comment_count": 0,
      "share_count": 329164
   },
   "id": "http://www.google.co.uk"
}
</code></pre>

<p>From this I could take the og_object ID and make the exact same call but using the ID this time instead to return scrape information containing the image url:</p>

<p><code>https://graph.facebook.com/v2.3/?id=383886459583&amp;access_token=xxxxx</code></p>

<pre><code>{
   "created_time": "2007-11-07T12:09:31+0000",
   "title": "Google",
   "type": "website",
   "description": "Happy St. David's Day 2016 #GoogleDoodle",
   "image": [
      {
         "height": 210,
         "url": "http://www.google.com/logos/doodles/2016/st-davids-day-2016-5676738174517248-thp.png",
         "width": 525
      }
   ],
   "is_scraped": true,
   "updated_time": "2016-03-01T10:58:02+0000",
   "url": "http://www.google.co.uk/",
   "id": "383886459583"
}
</code></pre>

<p>and from there I had an image url I could use however using the same method in 2.5 to get the image yields this</p>

<pre><code>{
   "created_time": "2007-11-07T12:09:31+0000",
   "title": "Google",
   "type": "website",
   "id": "383886459583"
}
</code></pre>

<p>Is there a way to get the image data in 2.5 using the ID or better still a way in which I can make a single call using the URL of the target link and return all of the og data at once?</p>

<p>Example of this in action would be </p>

<pre><code>var url = "https://graph.facebook.com/v2.3/{{{{id}}}}?access_token={{{{token}}}}";
var token = "xxxxx";
var id = "http%3A%2F%2Fwww.google.co.uk";
url = url.replace('{{{{token}}}}', token);

$.getJSON( url.replace('{{{{id}}}}', id), 
  function( data ) {
    console.log(data);
    if (data &amp;&amp; data.og_object &amp;&amp; data.og_object.id)
      $.getJSON( url.replace('{{{{id}}}}', data.og_object.id), 
        function( data ){
          console.log(data, data.image);
          //Do something with og data
        }
      );
  }
);
</code></pre>

<p>EDIT: Thanks for pointing out the declarative fields CBroe ( I updated the title to better reflect my desired answer ) but the duplicate you marked doesnt mention nested fields which would be necessary to fully answer this and limit this to one single API call although it did lead me down the right path. Complete solution for this which also returns the og data previously returned would be:</p>

<pre><code>https://graph.facebook.com/v2.5/http%3A%2F%2Fwww.google.co.uk?access_token=xxxxx&amp;fields=og_object{id,description,title,type,url,site_name,image,is_scraped,updated_time,audio,video,locale},id,share
</code></pre>

<p>Where <code>fields=</code> is our declarative fields and <code>og_object</code> is the top level JSON object - specifying this on its own however will only give us the trimmed down version of og_object minus the images. In order to get the images we need to drill into <code>og_object</code> to get the images field using the nesting syntax for declarative fields:</p>

<p><code>og_object{image}</code></p>

<p>and then we need to declare all the other og_object fields as they are no longer sent by default (plus a few others of interest), we would only get the image field</p>

<p><code>fields=og_object{id,description,title,type,url,site_name,image,is_scraped,updated_time,audio,video,locale},id,share</code></p>