【问题标题】:Facebook API offline newsfeed accessFacebook API 离线新闻源访问
【发布时间】:2012-01-11 06:06:55
【问题描述】:

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

在 PHP 中,我使用这一行来阅读新闻源:$result=$facebook->api("/me/home?access_token=".$access_token);

奇怪的是,当我在浏览器的 url 中输入访问代码时,它正在工作:

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

请记住,当用户授予您权限时,您会在 url 中得到这个: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,email,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);

但是获取提要不起作用。发帖的安全性应该比获取新闻提要更严格,对吧?

【问题讨论】:

  • 您在使用库函数时是否对访问令牌进行了urlencoding?在使用该函数之前可能需要对其进行编码。

标签: php facebook cron


【解决方案1】:

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

不用担心 facebook 库会为您完成工作...

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

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

会话已移至signed_request 参数(或服务器端的代码)

【讨论】:

    猜你喜欢
    • 2011-10-22
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多