facebook Oauth2.0接口集

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JV_Kevin/article/details/88987399

目录

前提条件:

1.登录鉴权

2.获取鉴权标示


之前搞了下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=AQAdRuzfxP58uZzzteyBeBK7J_MiN_hywA3NwT-CKZS9fXYnkUd99zmp0VtjsTLpyRgtGgaeiHVrBtwXRdvjMI1YLDOTBq3qrtNFJwcqun8Wpgu6SQCKDQvqJhZqCdAZUSAtjKgY1Xs5V_aayzYivUyGvZE8Ry9Wb4WeNvF_HIaeKZ6Cdwvc62V1hpopamqKw9g

字段说明: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官方开发文档上也有:

Friends: https://graph.facebook.com/me/friends?access_token=...
News feed: https://graph.facebook.com/me/home?access_token=...
Profile feed (Wall): https://graph.facebook.com/me/feed?access_token=...
Likes: https://graph.facebook.com/me/likes?access_token=...
Movies: https://graph.facebook.com/me/movies?access_token=...
Music: https://graph.facebook.com/me/music?access_token=...
Books: https://graph.facebook.com/me/books?access_token=...
Notes: https://graph.facebook.com/me/notes?access_token=...
Permissions: https://graph.facebook.com/me/permissions?access_token=...
Photo Tags: https://graph.facebook.com/me/photos?access_token=...
Photo Albums: https://graph.facebook.com/me/albums?access_token=...
Video Tags: https://graph.facebook.com/me/videos?access_token=...
Video Uploads: https://graph.facebook.com/me/videos/uploaded?access_token=...
Events: https://graph.facebook.com/me/events?access_token=...
Groups: https://graph.facebook.com/me/groups?access_token=...
Checkins: https://graph.facebook.com/me/checkins?access_token=...

所有facebook提供的接口都可以在官方提供的浏览器工具上测试(或者直接拼装好url在ff上测试即可看到返回效果,在IE上可能会提示下载):

官方提供的浏览器工具地址:http://developers.facebook.com/tools/explorer

官方论坛也不错:http://stackoverflow.com

猜你喜欢

转载自blog.csdn.net/JV_Kevin/article/details/88987399
今日推荐