简体   繁体   English

Facebook Open Graph-如何将发布JS函数重写为PHP

[英]Facebook Open Graph - how to rewrite publish JS function to PHP

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? 如何将这个JS函数重写为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? 如何在PHP中发布Open Graph操作?

I would recommend checking out the Facebook PHP SDK . 我建议您查看Facebook PHP SDK The documentation is pretty good (as far as Facebook goes) and it will abstract the messy file_get_contents() stuff. 该文档非常好(就Facebook而言),它将抽象出混乱的file_get_contents()内容。

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

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