简体   繁体   English

Facebook Graph API:在发布到FB之前获取链接标题/标题/图片/描述

[英]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. 我想显示从URL自动生成的名称,标题,描述和图片,然后再将其发布到我的应用程序中的Facebook。

This way the user can enter a URL and see what the defaults will be. 这样,用户可以输入URL并查看默认值。 If they wish to change the title/caption/picture/description before posting the link via the Graph API then they can. 如果他们希望在通过Graph API发布链接之前更改标题/标题/图片/说明,则可以。

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? 有没有办法通过Graph API做到这一点,还是我需要构建自己的简单抓取工具并自己寻找相关的meta标签?

Cheers, Dave 干杯,戴夫

-- -

Edit: Thanks @CBroe for the answer. 编辑:感谢@CBroe的答案。 Here's a dirty example in PHP for anyone else: 这是PHP中其他人的肮脏示例:

$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. 请参阅Facebook的Open Graph文档中的更新对象

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. 您可以对API进行POST调用以获取所有被抓取的URL,(成功后)它将以JSON格式返回“有关被抓取对象的所有信息”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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