如何使用CURL在Facebook页面上发布帖子,而不使用PHP中的SDK

如何使用CURL在Facebook页面上发布帖子,而不使用PHP中的SDK,第1张

概述我正在开发一个需要Facebook集成的 PHP项目.所以在我对代码进行处理之前,我正在使用Facebook Graph API资源管理器工具( https://developers.facebook.com/tools/explorer)对其进行测试.我现在在做的是. 1st Step Get the user access_token by using the button at the to 我正在开发一个需要Facebook集成的 PHP项目.所以在我对代码进行处理之前,我正在使用Facebook Graph API资源管理器工具( https://developers.facebook.com/tools/explorer)对其进行测试.我现在在做的是.

1st Step

Get the user access_token by using the button at the top left.

2nd Step

Make a GET request to "me/accounts" to get the page token and page ID.

3rd Step

Make a POST request to "{page_ID}/Feed" with the fIElds message={message} and access_token={page_token}

它工作得很好,并贴在我的Facebook粉丝页面上.但是当我尝试用这样的PHP代码替换“第三步”时

$data['message'] = "my message";$data['access_token'] = $page_access_token; //page token from 2nd step$ch = curl_init();curl_setopt($ch,CURLOPT_URL,'https://graph.facebook.com/{page_ID}/Feed');curl_setopt($ch,CURLOPT_VERBOSE,1);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,CURLOPT_POSTFIELDS,$data);curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);curl_setopt($ch,CURLOPT_FolLOWLOCATION,CURLOPT_POST,1);$resp = curl_exec($ch);curl_close($ch);$data_resp = Json_decode($resp);print_r($data_resp);

它告诉我这个错误.

stdClass Object ( [error] => stdClass Object ( [message] => (#200) Permissions error [type] => OAuthException [code] => 200 ) )

I set the permissions of manage_pages,publish_pages,publish_actions

解决方法 为CURLOPT_POSTFIELDS传递数组意味着cURL会将请求作为Content-Type multipart / form-data发送 – 但您需要application / x-www-form-urlencoded.

在$data数组上使用http_build_query,并将结果字符串用于CURLOPT_POSTFIELDS.

总结

以上是内存溢出为你收集整理的如何使用CURL在Facebook页面上发布帖子,而不使用PHP中的SDK全部内容,希望文章能够帮你解决如何使用CURL在Facebook页面上发布帖子,而不使用PHP中的SDK所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/1019784.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存