2011-01-06 120 views
2

我有用户授予的离线访问权限,会话过期= 0,因此它永不过期。我已将所有会话值(如access_code等)存储在数据库中。在存储这些值之后,我可以立即阅读新闻源。 2秒后,当我尝试使用这些存储的会话值读取用户的新闻传送时,它不起作用。 OAuthException:激活的访问令牌必须用于查询当前用户Facebook API离线新闻传送访问

在PHP中,我使用这条线来读取新闻源信息:$result=$facebook->api("/me/home?access_token=".$access_token);

奇怪的是,当我输入接入码的网址它正在工作:

https://graph.facebook.com/me/home?access_token= $ access_token。

记住,当用户给你的权限,你得到这个网址:http://example.it/home/newsfeed.php?perms=<permissionlist>&selected_profiles=<uid>&installed=1&session={session_key:<session_key>,uid:<uid>,expires:0,secret:<secret>,access_token:<firstpart>|<secondpart>|<third part>,sig:<sig>}

我的允许名单是这样的:

“friends_about_me,friends_education_history,friends_likes,friends_interests,friends_location, friends_religion_politics, friends_work_history,publish_stream,friends_activities,friends_events, friends_hometown,friends_location,user_interests,user_likes,user_events, user_about_me,user_status ,user_work_history,read_requests,read_stream,offline_access,user_religion_politics,电子邮件,user_groups“;

当我输入上面的任何浏览器的URL ,它给我的UID的新闻提要,因为newsfeed.php有PHP代码输出的新闻源。用户是否登录无关紧要。 IE甚至下载json结果作为文件

所以会话信息没有真正过期,它正在工作。但不知何故,我无法让Facebook相信我有正确的凭据来阅读新闻源。

任何帮助,非常感谢。请写下我如何重建会话价值并让Facebook相信我。

我的最终解决方案可以在我更新的博客上找到:http://akcora.wordpress.com/


我也忘了提,即使进给不工作,我仍然可以发布状态信息到用户的个人资料。这没有任何意义。我几乎可以肯定,我在编码方面犯了一个错误。例如,这是可以工作的状态发布代码:

$attachment = array(
     'access_token' => $access_token, 
      'message' => 'Did a Test Post :', 
       'name' => "Offline posting using stored tokens", 
       'link' => "http:somelink.com", 
       'description' => "This post was made using a stored access token", 
      'picture'=>"some.jpg", 
     ); 

$ret_code=$facebook->api('/'.$target.'/feed', 'POST', $attachment); 

但是获取提要不起作用。安全性应该比张贴新闻源更紧张,对吗?

+0

您使用的库函数时URL编码的访问令牌?在使用该功能之前可能需要对其进行编码。 – 2011-01-06 02:57:01

回答

0

将access_token作为api函数的参数发布,而不是作为url中的get参数。

不用担心Facebook库会为你做这项工作......

$facebook->api("me/feed",array(
    "access_token"=>$access_token 
)); 

并且顺便说一句 - 会话参数在新的OAuth身份验证方法中不再可用。

的会议转移到signed_request参数(或代码在服务器端)