简体   繁体   中英

Facebook Graph API: get a Link title/caption/picture/description before posting to FB

I would like to show the automatically generated name, caption, description and picture from a URL before posting it to Facebook in my app.

This way the user can enter a URL and see what the defaults will be. If they wish to change the title/caption/picture/description before posting the link via the Graph API then they can.

Is there a way to do this through the Graph API, or would I need to build my own simple scraper and look for relevant meta tags myself?

Cheers, Dave

--

Edit: Thanks @CBroe for the answer. Here's a dirty example in PHP for anyone else:

$url = 'http://google.com';
$ch = curl_init('https://graph.facebook.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,array(
    'id' => $url,
    'scrape' => true,
));
$data = json_decode(curl_exec($ch),true);
print_r($data);

example output

Array
(
    [url] => http://www.google.com/
    [type] => website
    [title] => Google
    [image] => Array
        (
            [0] => Array
                (
                    [url] => http://www.google.com/images/google_favicon_128.png
                )

        )

    [description] => Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
    [updated_time] => 2014-04-02T10:41:44+0000
    [id] => 381702034999
)

works in app:

See Updating Objects in Facebook's Open Graph documentation.

You can make a POST call to the API to get any URL scraped, and (on success) it will return you the “all the information about the object that was scraped” in JSON format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM