当前位置: 代码迷 >> Android >> Android运用facebook api(三)
  详细解决方案

Android运用facebook api(三)

热度:108   发布时间:2016-05-01 15:52:18.0
Android使用facebook api(三)

? 本文旨在介绍facebook的graph api?

? ?graph API 简介

? ? facebook的graph api是一套REST化的api,通过统一而稳定URL定义请访问数据对象,通过对http协议的GET,POST,DELETE三种请求进行数据操作的细分,响应JSON格式的数据包,组成了facebook的 graph api。

?

  • 首先看一个get请求的例子

https://graph.facebook.com/100000588112696,抓取User对象,格式客户端需要对response解析json格式,返回值如下。facebook-android/ios本身提供了sdk可以对json格式进行解析,其他平台需要额外写一套解析器来解析json格式。

{   "id": "100000588112696",   "name": "Jiqiang Bi",   "first_name": "Jiqiang",   "last_name": "Bi",   "link": "http://www.facebook.com/bijiqiang",   "username": "bijiqiang",   "gender": "male",   "locale": "zh_CN"}

?

?

  • 再来看一个post请求的例子

? https://graph.facebook.com/100000588112696/feed/ 创建一个post请求的http将参数传入

?

{ "caption": "realgodo",   "name": "realgodo",   "link": "http://realgodo.iteye.com",   "description": "Coming from my app",   "link": "http://www.facebook.com/bijiqiang",   "picture":"http://www.iteye.com/upload/logo/user/583286/acd59a73-6a14-3a17-a0ae-4ac30d5c43c8.png?1320570681"}

?

? ?返回的数据是

{	"id":?"100000588112696_302491803113754"?   }

?

?

? ?graph Api能做什么

?

  • ? ? ?抓取(fetch)

?

? ? ?首先调用调用https://graph.facebook.com/100000588112696?metadata=1&access_token=AAAAAAITEghMBAEZCbjrGZATmhq3YdIVb972ViUZBKe8KOdo5ZBk3SuZBjfTh0aS55snTMCA5dXaJSUmdqPiaGpXxH9u3qyb8YATyEa0kTfk5Yt2ELEMax

可以查看全部可以使用的graph api 包括必要的参数,一般就是access_token。

首先?看一组使用access_token的get型接口列表,主要是抓取数据。

 	 "home": "https://graph.facebook.com/100000588112696/home?access_token=",         "feed": "https://graph.facebook.com/100000588112696/feed?access_token=",         "friends": "https://graph.facebook.com/100000588112696/friends?access_token=",         "mutualfriends": "https://graph.facebook.com/100000588112696/mutualfriends?access_token=",         "family": "https://graph.facebook.com/100000588112696/family?access_token=",         "payments": "https://graph.facebook.com/100000588112696/payments?access_token=",         "activities": "https://graph.facebook.com/100000588112696/activities?access_token=",         "interests": "https://graph.facebook.com/100000588112696/interests?access_token=",         "music": "https://graph.facebook.com/100000588112696/music?access_token=",         "books": "https://graph.facebook.com/100000588112696/books?access_token=",         "movies": "https://graph.facebook.com/100000588112696/movies?access_token=",         "television": "https://graph.facebook.com/100000588112696/television?access_token=",         "games": "https://graph.facebook.com/100000588112696/games?access_token=",         "adaccounts": "https://graph.facebook.com/100000588112696/adaccounts?access_token=",         "likes": "https://graph.facebook.com/100000588112696/likes?access_token=",         "posts": "https://graph.facebook.com/100000588112696/posts?access_token=",         "tagged": "https://graph.facebook.com/100000588112696/tagged?access_token=",         "statuses": "https://graph.facebook.com/100000588112696/statuses?access_token=",         "links": "https://graph.facebook.com/100000588112696/links?access_token=",         "notes": "https://graph.facebook.com/100000588112696/notes?access_token=",         "photos": "https://graph.facebook.com/100000588112696/photos?access_token=",         "albums": "https://graph.facebook.com/100000588112696/albums?access_token=",         "events": "https://graph.facebook.com/100000588112696/events?access_token=",         "groups": "https://graph.facebook.com/100000588112696/groups?access_token=",         "videos": "https://graph.facebook.com/100000588112696/videos?access_token=",         "picture": "https://graph.facebook.com/100000588112696/picture?access_token=",         "inbox": "https://graph.facebook.com/100000588112696/inbox?access_token=",         "outbox": "https://graph.facebook.com/100000588112696/outbox?access_token=",         "updates": "https://graph.facebook.com/100000588112696/updates?access_token=",         "accounts": "https://graph.facebook.com/100000588112696/accounts?access_token=",         "checkins": "https://graph.facebook.com/100000588112696/checkins?access_token=",         "apprequests": "https://graph.facebook.com/100000588112696/apprequests?access_token=",         "friendlists": "https://graph.facebook.com/100000588112696/friendlists?access_token=",         "friendrequests": "https://graph.facebook.com/100000588112696/friendrequests?access_token=",         "permissions": "https://graph.facebook.com/100000588112696/permissions?access_token=",         "notifications": "https://graph.facebook.com/100000588112696/notifications?access_token=",         "scores": "https://graph.facebook.com/100000588112696/scores?access_token="	
?
  • 查询功能(search)

?

All public posts: https://graph.facebook.com/search?q=watermelon&type=postPeople: https://graph.facebook.com/search?q=mark&type=userPages: https://graph.facebook.com/search?q=platform&type=pageEvents: https://graph.facebook.com/search?q=conference&type=eventGroups: https://graph.facebook.com/search?q=programming&type=groupPlaces: https://graph.facebook.com/search?q=coffee&type=place&center=37.76,122.427&distance=1000Checkins: https://graph.facebook.com/search?type=checkin
?

?

  • ? ?发布功能(publish)

https://graph.facebook.com/${PROFILE_ID}/feed

?

https://graph.facebook.com/${OBJECT_ID}/commentshttps://graph.facebook.com/${OBJECT_ID}/likeshttps://graph.facebook.com/${PROFILE_ID}/noteshttps://graph.facebook.com/${PROFILE_ID}/linkshttps://graph.facebook.com/${PROFILE_ID}/eventshttps://graph.facebook.com/${EVENT_ID}/attendinghttps://graph.facebook.com/${EVENT_ID}/maybehttps://graph.facebook.com/${EVENT_ID}/declinedhttps://graph.facebook.com/${PROFILE_ID}/albumshttps://graph.facebook.com/${ALBUM_ID}/photoshttps://graph.facebook.com/${PROFILE_ID}/checkins

? ${PROFILE_ID}是User.id,${ALBUM_ID}是Album.id

?

  • ? ?删除功能

?

https://graph.facebook.com/${ID}?access_token=...   HTTP/1.1

? ? ${ID}是对象的主键,规则是${User.id}_${Object.id}

?

? ? 其他的功能类别还包括分析(Analytics),批量操作(Batch Requests)

?

?

  • ? graph api class介绍

?

? ? ?Achievement??附件

? ? ?用户的附件

?

? ? ?Album 相册

? ? ?招聘相册

?

? ? ?Application应用程序

? ? ?在facebook注册的应用程序

?

? ? ?Checkin签到

?

? ? ?Comment评论

?

? ? ?Domain域名

?

? ? ?Event facebook事件

?

? ? ?FriendList 朋友列表

?

? ? ?Group 群组

?

? ? ?Insights 统计分析

? ? ?app,页面,域名的统计分析结果

?

? ? ?Link 链接

? ? ?分享的链接

?

? ? ?Message 消息

? ? ?线程内消息

?

? ? ?Note提示

?

? ? ?Page 页面

?

? ? ?Photo照片

?

? ? ?Post 涂鸦墙内容

?

? ? ?Question 问题

? ? ?用户提问

?

? ? ?QuestionOption 备选答案

? ? ?用户提问的一个备选答案

?

? ? ?Review反馈

? ? ?对app的反馈

?

? ? ?Status message 涂鸦墙消息

?

? ? ?Subscription订阅

?

? ? ?Thread 消息线程

?

? ? ?User 用户

?

? ? ?Video 视频

?

?

?

  相关解决方案