php Facebook 验证访问令牌时出错:会话已在 unix 时间过期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5827901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Error validating access token: Session has expired at unix time
提问by Anandhan
I have integrated the offline wall posting for the users of my website who have linked their FB accounts with there user details. I have stored there FB-id, FB-Access token in my database and by using the PHP-SDK libraries I had integrated the feed wall posting in the website. Everything worked very well with all users getting the messages on there facebook wall. But today all the things went in vain as it throws various kinds of error. I have been searching for more documents but can't find the exact relevant solution for this issues.
我已经为我的网站用户整合了离线墙贴,这些用户已将他们的 FB 帐户与那里的用户详细信息相关联。我已经在我的数据库中存储了 FB-id、FB-Access 令牌,并通过使用 PHP-SDK 库在网站中集成了提要墙发布。一切都很好,所有用户都在 facebook 墙上收到消息。但是今天所有的事情都白费了,因为它抛出了各种各样的错误。我一直在寻找更多文档,但找不到针对此问题的确切相关解决方案。
Lines of code i have used for FB-Wall Posting
我用于 FB-Wall Posting 的代码行
$usid=$pageinfo['user']['id_facebook'];
$accestoken=$pageinfo['user']["facebook_accesstoken"];
if($pageinfo['user']['user_fbtoken']=='1')
$attachment = array(
'access_token' => $accestoken,
'message' => "myTaste || real restaurant reviews, share your taste on myTaste",
'name' => "My Favorite Restaurant is ".$business['name'].$business['location']['city']."-What is yours? ",
'link' => $business['personal_url'],
'description' => "",
'picture'=> "http://googima.com/images/mysite.gif"
);
$facebook->api("/".$usid."/feed", "post",$attachment);
}
Error messages:
错误信息:
Uncaught OAuthException: Error validating access token: Session has expired at unix time
Uncaught OAuthException: (#210) User not visible thrown in /hsphere/local/home/mysite.com/include/3rdparty/facebook-php-sdk/src/facebook.php
The main idea of doing this offline wall posting is user is not going to asked for the FB login each time when do some reviews in the website. It need to post automatically by using the FB details that we have stored in the user table.
做这个离线墙贴的主要思想是用户不会每次在网站上做一些评论时都要求登录 FB。它需要使用我们存储在用户表中的 FB 详细信息自动发布。
回答by ifaour
Once you grant the publish_stream
permission, no need for the access_token
. So removing it and using something like this would work even without a valid session (just an example):
一旦您授予publish_stream
权限,就不需要access_token
. 因此,即使没有有效的会话(只是一个例子),删除它并使用类似的东西也可以工作:
$params = array(
'message' => "Test Message",
'picture'=> "http://path/to/image.jpg"
);
$post_id = $facebook->api("/$uid/feed", "post",$params);
For more information refer to this answer(EDIT 4). Kudos to @zerkms for this info btw!
有关更多信息,请参阅此答案(编辑 4)。顺便说一句,感谢@zerkms 提供此信息!
回答by zerkms
Access token is not permanent in facebook oauth implementation. You need to renew it in the begin of your working session
访问令牌在 facebook oauth 实现中不是永久性的。您需要在工作会议开始时更新它
More details at: http://developers.facebook.com/docs/authentication/
更多详细信息,请访问:http: //developers.facebook.com/docs/authentication/