I am using this scheme for publishing my action to the timeline:
function postCook()
{
FB.api(
'/me/app_url:action',
'post',
{ object: 'url address' },
function(response) {
if (!response || response.error) {
console.log(response);
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
<input type="button" value="Cook" onclick="postCook()" />
How could I rewrite this JS function into PHP? I've tried something like this (what I've found here ):
$myurl = 'https://graph.facebook.com/me/url_app_name:action?object=url_address&access_token=ACCESS_TOKEN&method=post';
$result = file_get_contents($myurl);
But this returns me the error
Warning: file_get_contents(content of $myurl) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in...
How could I publish Open Graph action in PHP?
I would recommend checking out the Facebook PHP SDK . The documentation is pretty good (as far as Facebook goes) and it will abstract the messy file_get_contents() stuff.
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.