Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用脚本发布到Facebook墙,并自动登录_Facebook_Facebook Graph Api - Fatal编程技术网

使用脚本发布到Facebook墙,并自动登录

使用脚本发布到Facebook墙,并自动登录,facebook,facebook-graph-api,Facebook,Facebook Graph Api,当我使用PHP脚本和Graph API登录时,我可以在我的Facebook网页上发表文章。我在我的主网站上有一个新闻页面,我想把新闻发布到Facebook上,因为它们被发布到我的网站上,我猜这与使用API的人数是相反的 我已为FB应用程序授予脱机访问权限并将流发布到我的FB帐户 如果我关闭FB会话并尝试从我的新闻页面发帖,Facebook将显示一个登录页面。我已经允许访问,所以我不知道我还缺少什么 如果我正确理解了你的问题,我想我刚刚解决了同样的问题。我不能完全使用graph API来解决这个问

当我使用PHP脚本和Graph API登录时,我可以在我的Facebook网页上发表文章。我在我的主网站上有一个新闻页面,我想把新闻发布到Facebook上,因为它们被发布到我的网站上,我猜这与使用API的人数是相反的

我已为FB应用程序授予脱机访问权限并将流发布到我的FB帐户


如果我关闭FB会话并尝试从我的新闻页面发帖,Facebook将显示一个登录页面。我已经允许访问,所以我不知道我还缺少什么

如果我正确理解了你的问题,我想我刚刚解决了同样的问题。我不能完全使用graph API来解决这个问题,但graph API和遗留rest API的组合解决了这个问题。一旦您授予应用程序发布到facebook页面墙的权限,以下代码应满足您的要求:

$url = "https://graph.facebook.com/oauth/access_token";
$client_id = "XXXXXXXXXXXXXX";
$client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$postString = "client_id=$client_id&client_secret=$client_secret&type=client_cred";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$token = curl_exec($curl);
curl_close($curl);

$message = rawurlencode($description.'. Notes:'.$notes);
$url = "https://api.facebook.com/method/stream.publish";
$postString = "message=$message&uid=XXXXXXXXXXXXX&$token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$response = curl_exec($curl);
curl_close($curl);
没有什么值得注意的。 1.rest api$postString中的uid是facebook页面的uid。您不需要目标id,因为当uid属于某个页面时,它只能发布到自身。 2.您的$message必须是rawurlencoded,因为它是RESTAPI接受的表单。 3.这将作为你的应用程序发布到你的页面,而不是作为发布到你网站的用户。要做到这一点,您需要拥有所有用户的发布流权限

希望这有帮助