Facebook离线访问一步一步 [英] Facebook offline access step-by-step

查看:163
本文介绍了Facebook离线访问一步一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


更新:Facebook offline_access 正在弃用权限。有关详细信息,请参阅官方文档

您将一直持续到 2012年5月1日,届时此设置将被禁用
。请参阅开发人员路线图了解更多信息。







在脸书和谷歌上搜索1天后,进行最新的工作, >做一些看似简单的事情的方式:



我正在寻找一个分步说明来为facebook用户取得offline_access,然后使用(会话键)检索离线&不在浏览器中的朋友和个人资料数据。



优先在Fb Java API中执行此操作。



谢谢。



是的,我检查了Facebook维基。



更新:任何人?



this:
http://www.facebook.com/authorize.php?api_key=<api-key>& ; v = 1.0& ext_perm = offline_access
给我offline_Access,但是如何检索session_key?



为什么不能Facebook只是做简单的文档,我的意思是有600人在那里工作?



看似相同的问题:

不回答如何检索会话密钥



编辑:我还是坚持下去我猜没有人真的尝试过这样的批量访问...

解决方案

使用新的Facebook Graph API,事情有一点更简单但远远不及文献记载。这是我做的只能从服务器端加载墙壁帖子(不是浏览器会话的一部分)php脚本:


  1. 创建一个Facebook应用程序,如果您还没有一个可用于此项目的
    http://www.facebook.com/developers/apps.php#!/开发者/ createapp.php
    - 并设置沙盒/开发者模式! @高级设置>沙箱模式>启用(只允许您的应用程序的开发人员看到它。)
    您将需要您的开发者帐户摘要中列出的应用程序ID(APP_ID)和秘密密钥(SECRET_KEY)应用程序,但不是旧的API密钥。


  2. 加载到浏览器中,已经登录到fb作为您希望服务器端应用程序连接的帐户,以及点击允许所需的权限:
    https://graph.facebook.com/oauth/authorize?client_id=APP_ID&scope=offline_access,read_stream&redirect_uri=http://www .facebook.com / connect / login_success.html


  3. 从生成的url的查询字符串中复制code参数,使用in:
    https://graph.facebook.com/oauth/access_token?client_id=APP_ID&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret= APP_SECRET& code = CODE_FROM_2
    并在生成的页面中复制access_token =的右侧的文本,其结构如下:APP_ID | HEXNUM-USER_ID | WEIRD_KEY


  4. 现在可以从图形API或经典休闲api中下载你的誓言访问令牌就是ala(其中SOURCE_ID是用户/组的facebook id /您正在查找的内容):

     <?php 
    $ stream = json_decode(file_get_contents(https://api.facebook.com/method/stream.get?source_ids=SOURCE_ID&access_token=ACCESS_TOKEN&格式= JSON));
    var_dump($ stream);
    //这个给出一个500内部服务器错误从http get如果任何一个字段无效,但只在php,而不是加载在浏览器...奇怪。
    $ feed = json_decode(file_get_contents(https://graph.facebook.com/SOURCE_ID/feed?fields=id,from,created_time,link,type&access_token=ACCESS_TOKEN));
    var_dump($ feed);
    ?>


注意到图api和rest api返回不仅仅是不同的结构,而且还有不同的信息 - 所以在这里,我更喜欢其余api(第一个)的结果,尽管我喜欢能够限制新图形API(第二个)的字段。 p>

查看 http://developers.facebook。 com / docs / authentication / 在官方(稀疏)细节中的请求扩展权限和认证Web应用程序中的用户部分。



如果你想这样做,即以编程方式,这里是步骤2 + 3的自动化版本:



将它放在您的网络服务器上,如facebook_access_token.php:

 <?php $ token = explode('=',file_get_contents(https://graph.facebook.com/oauth / CLIENT_ID的access_token = APP_ID&安培; REDIRECT_URI = HTTP:// $ _ SERVER [SERVE R_NAME] $ _ SERVER [PHP_SELF]& client_secret = APP_SECRET& code =。 
(get_magic_quotes_gpc()?stripslashes($ _ GET ['code']):$ _GET ['code'])))
echo $ token [1];
//存储这个访问令牌,在db中登录您的站点上的用户,不要滥用他们的信任! ?>

直接浏览器中的用户:
https: /graph.facebook.com/oauth/authorize?client_id=APP_ID&scope=offline_access,read_stream&redirect_uri=http://www.example.com/facebook_access_token.php


UPDATE: Facebook offline_access permission is being deprecated. Please refer to the official documentation for more information.
You'll have till May 1, 2012, at which date this setting will be disabled. refer to the Developer Roadmap for more info.


After searching literally 1 day on facebook and google for an up-to-date and working way to do something seemingly simple:

I am looking for a step-by-step explanation to get offline_access for a user for a facebook app and then using this (session key) to retrieve offline & not within a browser friends & profile data.

Preferrably doing this in the Fb Java API.

Thanks.

And yes I did check the facebook wiki.

Update: Anyone?

this: http://www.facebook.com/authorize.php?api_key=<api-key>&v=1.0&ext_perm=offline_access gives me offline_Access, however how to retrieve the session_key?

Why can't facebook just do simple documentation, I mean there are like 600 people working there?

The seemingly same question: Getting offline_access to work with Facebook Does not answer how to retrieve the session key

Edit: I am still stuck with that. I guess nobody really tried such a batch access out yet...

解决方案

With the new Facebook Graph API, things got a bit simpler but far less well documented. Here's what I did to be able to load my wall posts as me from a server side only (not part of a browser session) php script:

  1. create a facebook application, if you don't already have one usable for this project http://www.facebook.com/developers/apps.php#!/developers/createapp.php -- and set sandbox/developer mode on! @ Advanced Settings > Sandbox Mode > Enable (Lets only the developers of your application see it.) You'll need the Application ID (APP_ID) and Secret Key (SECRET_KEY) that are listed on your developer account summary of that application but not the old API Key.

  2. load in your browser, already logged in to fb as the account you want your server side app to connect as, and click "allow" for the requested permissions: https://graph.facebook.com/oauth/authorize?client_id=APP_ID&scope=offline_access,read_stream&redirect_uri=http://www.facebook.com/connect/login_success.html

  3. copy the "code" parameter from the resulting url's query string, use that in: https://graph.facebook.com/oauth/access_token?client_id=APP_ID&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=APP_SECRET&code=CODE_FROM_2 And copy the right hand side of access_token= in the resulting page's text, which will be in the structure of: APP_ID|HEXNUM-USER_ID|WEIRD_KEY

  4. now download either from the graph api or the classic rest api using the oath access token you just got ala (where SOURCE_ID is the facebook id for the user/group/whatever that you are looking up):

    <?php
    $stream = json_decode(file_get_contents("https://api.facebook.com/method/stream.get?source_ids=SOURCE_ID&access_token=ACCESS_TOKEN&format=json"));
    var_dump($stream);
    // this one gives a 500 internal server error from the http get if any of the fields are invalid, but only in php, not when loaded in a browser... weird.
    $feed = json_decode(file_get_contents("https://graph.facebook.com/SOURCE_ID/feed?fields=id,from,created_time,link,type&access_token=ACCESS_TOKEN"));
    var_dump($feed);
    ?>
    

Noting that the graph api and rest api return not just different structures, but also different information -- so here, I prefer the results from the rest api (the first one) even though I like being able to restrict the fields in the new graph api (the second one).

Look at http://developers.facebook.com/docs/authentication/ in the sections "Requesting Extended Permissions" and "Authenticating Users in a Web Application" for the official (sparse) details.

If you want to do this routinely, i.e. programmatically, here's the automated version of steps 2+3:

Put this on your web server as "facebook_access_token.php":

<?php $token = explode('=', file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=APP_ID&redirect_uri=http://$_SERVER[SERVER_NAME]$_SERVER[PHP_SELF]&client_secret=APP_SECRET&code=" . 
(get_magic_quotes_gpc() ? stripslashes($_GET['code']) : $_GET['code']))); 
echo $token[1]; 
// store this, the access token, in the db for the user as logged in on your site -- and don't abuse their trust! ?>

And direct users in their browsers to: https://graph.facebook.com/oauth/authorize?client_id=APP_ID&scope=offline_access,read_stream&redirect_uri=http://www.example.com/facebook_access_token.php

这篇关于Facebook离线访问一步一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆