您的位置:首页 > 其它

Facebook Oauth2.0 API调用方法

2016-03-26 23:06 92 查看
这些天搞了下Facebook API的东东,在官方网站下弄了一些接口,下面简单的把facebook的调用流程以及常用接口书序一下 :-)

当然在使用facebook api之前要有facebook账号以及在facebook上注册一个自己的应用
1.登录鉴权 https://graph.facebook.com/oauth/authorize?client_id=8888888888888&redirect_uri=http://www.mywebsite.com&scope=user_about_me,user_activities,user_birthday,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationships,user_religion_politics,user_status,user_videos,user_website,user_work_history,read_friendlists,read_requests,publish_stream,create_event,rsvp_event,sms,offline_access,friends_about_me,friends_activities,friends_birthday,friends_education_history,friends_events,friends_groups,friends_hometown,friends_interests,friends_likes,friends_location,friends_notes,friends_online_presence,friends_photo_video_tags,friends_photos,friends_relationships,friends_religion_politics,friends_status,friends_videos,friends_website,friends_work_history,read_stream,photo_upload 字段说明:client_id :注册应用后即可得到
redirect_uri :登录鉴权回调页面
scope :允许用户访问的facebook模块(可在官网上找到齐全的)

登录鉴权之后会回调到你给定的redirect_uri,此时会在你的url后面带上facebook给定的结果参数,其中auth_token是我们下面需要的
2.获取鉴权标示
https://graph.facebook.com/oauth/access_token?client_id=8888888888888&redirect_uri=http://www.mywebsite.com&client_secret=3dfdsa5425fdsa7554520720df8&code=............
字段说明:client_id :注册应用后即可得到
redirect_uri :回调页面

client_secret:注册应用后即可得到
code :在登录鉴权后返回的auth_token值

这里接口会类似第一步一样返回给我们一个access_token的值,下面我们就需要用这个access_token值做如下操作了(access_token值可存储起来,下次继续使用):
A. 查询个人信息 https://graph.facebook.com/me?access_token=... 备注:“me”可替换成任意用户的ID。
可添加fields参数查询相应的个人信息字段,字段集如下:
fields=id,name,first_name,middle_name,last_name,gender,locale,languages,link,username,third_party_id,timezone,updated_time,verified,bio,birthday,education,email,hometown,interested_in,location,political,favorite_athletes,favorite_teams,quotes,relationship_status,religion,significant_other,video_upload_limits,website,work,picture 用户自定义图片还可以这样获得: https://graph.facebook.com/me/picture?access_token=... B. 查询好友 https://graph.facebook.com/me/friends?access_token=... 备注:“me”可替换成任意用户的ID。 或者可以用FQL形式: https://graph.facebook.com/fql?q=SELECT uid2 FROM friend WHERE uid2 = me()
C. 查询个人动态信息 https://graph.facebook.com/me/feed?access_token=... 备注:“me”可替换成任意用户的ID。 或者可以用FQL形式: https://graph.facebook.com/fql?q=SELECT status_id, time, source, message FROM status where uid = me()&access_token=...
D. 查询用户所有的动态信息(包括自己/朋友/系统) https://graph.facebook.com/me/home?access_token=... 备注:“me”可替换成任意用户的ID。 或者可以用FQL形式: https://graph.facebook.com/fql?q=SELECT%20status_id,%20time,%20source,%20message%20FROM%20status%20where%20uid%20in%20%28SELECT%20uid1,%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me%28%29%29&access_token=... E. 发表动态
需要用到post方式提交,url为: https://graph.facebook.com/me/feed/ 参数为:
message = "add news feed test!!!"; access_token = "...";

以下是一些比较常用的接口提供,facebook官方开发文档地址:
http://developers.facebook.com/docs/reference/api/ 所有facebook提供的接口都可以在官方提供的浏览器工具上测试(或者直接拼装好url在ff上测试即可看到返回效果,在IE上可能会提示下载):
官方提供的浏览器工具地址:http://developers.facebook.com/tools/explorer
官方论坛也不错:http://stackoverflow.com
Twitter API调用例子:http://download.csdn.net/detail/dingding5060/3715744
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: