开发者

Open Graph Publishing

I'll try my best not to make this too long winded. Basical开发者_运维百科ly, with Open Graph, if a user 'likes' a web page (in my example, a blog), you can set it up so that when a new post is added, an entry is shown in their news feed linking to it.

For how this is allegedly done, see here: https://developers.facebook.com/blog/post/465/

Basically, you add OG meta tags to your site, create an app, link to the app_id in the OG tags, like the page and it will then create a kind of invisable facebook page that only the admins can see - users get taken to the site instead. The crutial thing is, because people 'like' this page, you can write posts from that page and the users will see it.

The weird thing is, this worked for me yesterday but it's suddenly stopped working. Nothing's changed, it just stopped working.

So I've created a blog, added the correct meta OG tags, created an app, added the fb:app_id tag to the blog containing the app ID.

The code in the example can be split into two parts. Firstly, getting the access token:

$access_token_url = "https://graph.facebook.com/oauth/access_token"; 
$parameters = "grant_type=client_credentials&client_id=" . $app_id . "&client_secret=" . $app_secret;
$access_token = file_get_contents($access_token_url . "?" . $parameters);

That works fine, it returns an access token. However, the second part of the example, posting from the facebook page doesn't work.

$apprequest_url = "https://graph.facebook.com/feed";
$parameters = "?" . $access_token . "&message=" . $mymessage . "&id=" . urlencode($ogurl) . "&method=post";
$myurl = $apprequest_url . $parameters;
$result = file_get_contents($myurl);

The error I get is: (#200) The user hasn't authorized the application to perform this action

Has Facebook changed their API in the last 24 hours or something?

Any help would be much appreciated as this is driving me completely nuts!

Cheers Pete


Does the user authorize your app? You need to authenticate the user the first time so the app can post on his behalf: http://developers.facebook.com/docs/authentication/

You will need to request the publish_stream permission. Here is a reference: http://developers.facebook.com/docs/reference/api/permissions/

After that you can follow the examples to post or use what you currently had. (remember to keep the access_token)

Here is an example with JS https://developers.facebook.com/docs/reference/dialogs/feed/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜