how to post facebook user wall/ page status by a single user only no app install for other users

蓝咒 提交于 2019-12-03 21:34:22

问题


I am working on a site and i need to post page links from that site to a special user wall or page if something is published on it which means i only need one user to post that question.

the problem which i am facing is access token since i am not trying to show facebook login page in front of website traffic. its not like sharing on user wall we are basically trying to post status on a page automatically so any help for this problem will be appreciated.

i am using the following code which seems to work fine as long as the access token for the page is valid but i need to make something permanent so that i can add all the info in the php code hardcoded and it work for some weeks at-least without changing the api key or token

$appid = 'code';
$appsecret = 'code';
$wall= $pageId = 'code';

$token='page token';

$facebook = new Facebook(array('appId'  => $appid, 'secret' => $appsecret, 'cookie' => true));

$params=array( 'message' => $msg,'name' => $title, 'caption' => $title, 'link' =>$uri,'description' => $desc, 'picture' => $pic, 'access_token' => $token,'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) );

$result = $facebook->api($wall.'/feed/','post',$params);

if i make token from the graph api debug page then it works fine but after some time i got the message "OAuthException: An active access token must be used to query information about the current user."

i am really desperate to find something solid for it.

thank you


回答1:


You can write a backend script (maybe a cron job using the FB PHP-SDK) that runs as the special user and makes the desired FB api calls. For this, you will want to use a long-lived access token, which needs to be renewed every 60 days. You might also try your FB api calls using an App Access Token, which do not expire but also do not support all FB publishing and other operations.




回答2:


To post to someones wall (or perform any action with the open graph) you must be authenticated with facebook as somebody in their graph or an application that they have granted permission to.

You should look at the permissions that can be set using the oauth scope attribute...

https://developers.facebook.com/docs/reference/dialogs/oauth/

To me it looks like they will need to grant your application publish_stream if you want to write to their friends walls as well as the user that you are authenticated as.

https://developers.facebook.com/docs/reference/login/extended-permissions/



来源:https://stackoverflow.com/questions/13113528/how-to-post-facebook-user-wall-page-status-by-a-single-user-only-no-app-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!