반응형
Graph API
Core Concepts > Graph API

원문 : http://developers.facebook.com/docs/reference/api/

- 초반부분 번역하다가 중반쯤부터 듬성듬성 건너뛰었습니다. ㅎㅎ

 페이스북의 핵심은 소셜 그래프 입니다. ; 그래프는 그들이 관심을 가지고 있는 사람 그리고 연결(관계/인맥?)과 같은 모든 것을 포함합니다. 그래프 API는 페이스북 소셜 그래프의 간단하고 한결같은 관점을 표현하고, 그래프(예를들면, 사람,사진,이벤트,페이지) 안의 객체들과 그들 사이의 관계(예를들면, 친구관계, 공유물그리고 사진태크)들을 일관되게 표현합니다.

 소셜 그래프에서 모든 객체들은 유일한 ID를 가지고 있습니다. 당신은 https://graph.facebook.com/ID 로 요청함으로써 객체의 속성들에 접근할 수 있습니다. 예를 들면, 페이스북 플랫폼의 공식페이지는 id 19292868552 인데, 그래서 당신은 https://graph.facebook.com/19292868552 로 객체를 가져올 수 있습니다.

{
   "name": "Facebook Platform",
   "type": "page",
   "website": "http://developers.facebook.com",
   "username": "platform",
   "founded": "May 2007",
   "company_overview": "Facebook Platform enables anyone to build...",
   "mission": "To make the web more open and social.",
   "products": "Facebook Application Programming Interface (API)...",
   "likes": 449921,
   "id": 19292868552,
   "category": "Technology"
}

다른 대안으로는,  ID 처럼 사용자이름(username)으로 사람과 페이지에 접근할 수 있습니다. "platform"이 해당페이지에 대한 사용자이름이기 때문에, https://graph.facebook.com/platform 은 여러분이 예상하는 것을 반환할 것입니다.  모든 응답들은 JSON 객체일 것입니다.

페이스북의 모든 객체들은 다 같은 방법으로 접근할 수 있습니다.


페이스북 소셜 그래프의 모들 객체들은 관계를 통해서 각자 서로에게 연결되어져 있습니다. Bret Taylor 는 코카콜라 페이지의 팬이고, Bret Taylor 와 Arjun Banker 는 친구입니다. 우리는 우리의 API로 그러한 관계 연결들은 가져옵니다. 당신은 객체들 사이의 연결을 https://graph.facebook.com/ID/CONNECTION_TYPE URL구조를 사용해서 조사할 수 있습니다. 그 연결들은 아래에 있는 사람들과 페이지들을 위해 제공되어 집니다.


우리는 서로 다른 객체들에 대해서 다른 연결 형을 지원합니다. 예를 들면, 당신은 https://graph.facebook.com/331218348435/attending?access_token=....를 가져옴으로써 SXSW(ID #331218348435)인 페이스북 개발자 모임에 소속해 있는 모든 사람들의 목록을 가져올 수 있습니다.

우리가 지원하는 객체와 연결들의 모든 다른 형들은 그래프 API 참조문서(Graph API reference documentation)에 포함되어져 있습니다. 가장 쉽게 시작하는 방법은 Graph API Explorer 로 탐색하는 것입니다.


Authorization

 그래프 API는 당신이 객체와 관련한 모든 공공(공개된?) 정보에 쉽게 접근할 수 있도록 허용해 주는 것과 같은 것입니다.  예를 들면, https://graph.facebook.com/btaylor (Bret Taylor) 는 Bret 에 관한 모든 공개된 정보를 반환합니다. 예를 들면, 사용자의 이름, 가족이름 그리고 개인정보사진들은 공개적으로 이용할 수 있습니다.

 사용자에 대한 추가적인 정보를 얻기 위해서, 첫째로 당신은 사용자들의 권한을 얻어야만 합니다. 높은 레벨에서, 당신은 페이스북 사용자에 대한 access_token을 가질 필요가 있습니다. 당신이 사용자에 대한 access_token을 획득한 후에, 당신은 권한 있는 요청들을 수행할 수 있습니다. 

https://graph.facebook.com/220439?access_token=...

예를 들면 https://graph.facebook.com/btaylor?access_token=... (Bret Taylor) 은 Bret Taylor에 대한 추가적인 정보들을 반환합니다. 

 Graph API는 인증을 위해 OAuth2.0을 사용합니다. 페이스북의 OAuth2.0을 구현한 인증가이드라인을 읽고 사용자로부터 어떻게 권한을 요청하고 access token을 얻는지 확인하세요.

 access token을 얻는데는 추가적인 권한이 필요하지 않지만 이메일이나 현재 회사정보 등을 가져오려면 추가적인 권한 정보가 필요할 것입니다.

Page Login
manage_pages permission.

App Login 
app access token.

Reading

Selection
https://graph.facebook.com/bgolub?fields=id,name,picture 처럼 field param을 사용해서 원하는 요소들에 대한 값을 받을 수 있습니다.
https://graph.facebook.com?ids=arjun,vernal 단일 쿼리로 복수의 객체를 받을 수 있습니다.
ids param은 url도 받습니다. https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/

Pictures

아래와 같이 /picture 접미어를 사용해서 프로필 사진을 가져올 수 있습니다.:

Paging
필터하거나 페이징 할 수도 있습니다.

Dates
date_format param을 사용하는데 ISO-8601로 반환되며 php date function으로도 받아집니다. 예는 다음과 같습니다.  http://graph.facebook.com/platform/feed?date_format=U

Introspection
객체 URL에 metadata=1을 붙이면 객체가 가진 모든 연결정보들을 가져올 수 있습니다.  https://graph.facebook.com/331218348435?metadata=1

Real-Time updates 
real-time updates는 앱의 사용자들에 대한 바뀐 정보들에 대해 가져올 수 있는 권한을 제공합니다. 

Searching

social graph 상의 모든 공용 객체들을 검색할 수 있습니다. : 

You can search over all public objects in the social graph with https://graph.facebook.com/search. The format is:

https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE

아래와 같은 객체 형식들도 지원합니다.:

fields= URL paramete의 사용:

Some fields such as id, and start_time for events, are always returned.

homeconnection URL을 사용한 뉴스피드 검색:


Publishing
access token을 사용한 HTTP POST 요청을 사용해서 페이스북 그래프에 게재할 수 있습니다.
https://graph.facebook.com/arjun/feed:
curl -F 'access_token=...' \
     -F 'message=Hello, Arjun. I like this new API.' \
     https://graph.facebook.com/arjun/feed

각각 /comments 나 /likes 를 사용해서 보낼 수 있습니다.
 
https://graph.facebook.com/OBJECT_ID/comments 
 
https://graph.facebook.com/OBJECT_ID/likes :

curl -F 'access_token=...' \
     https://graph.facebook.com/313449204401/likes


Deleting
 
객체 url에 대한 HTTP DELETE 요청을 실행함으로써 객체를 삭제할 수 있습니다. 예시,

DELETE https://graph.facebook.com/ID?access_token=... HTTP/1.1

 POST 요청을 사용해서실행하는 방법이 있습니다. method=delete 를 param 값으로 사용하면 되는데 예시는 아래와 같습니다.
https://graph.facebook.com/COMMENT_ID?method=delete
.

Analytics

Insights
 로 앱에 대한 통계를 알 수 있고 데이터를 받으려면 먼저 app access token 가 있어야 합니다. 여러분의 앱이 access token을 가지고 있을 때 다음의 url로 분석 데이터를 받을 수 있습니다.
https://graph.facebook.com/app_id/insights?access_token=...

API를 통해서 다양한 분석 데이터들을 이용할 수 있으며 다음은 앱의 캔버스 페이지에 대한 노출수에 대한 url 입니다.:

https://graph.facebook.com/app_id/insights/application_canvas_views/day?access_token=...

또한 시간 범위에 대한 데이터도 이용할 수 있ㅅ브니다.:

https://graph.facebook.com/app_id/insights?access_token=...&since=yesterday

/insights URL 을 기반으로  Insights  상품을 탐색할 수 있습니다.


Batch Request

여러분의 앱이 중요한 많은 양의 데이터에 접근하거나 여러 객체들의 변경을 할 때, 다중의 HTTP 요청을 생성하는 것보다 이러한 연산들을 결합하는 좀 더 중요합니다.

요청들을 일괄처리 하려면, documentation 을 읽어보세요.
Concepts

If your application needs the ability to access significant amounts of data in a single go - or you need to make changes to several objects at once, it is often more efficient batch your queries rather than make multiple individual HTTP requests. To enable this, the Graph API support Batching. Batching allows you to pass instructions for several operations in a single HTTP request.

Permissions to access GRAPH API fields and connections.

The Graph API supports real-time updates to enable your application using Facebook to subscribe to changes in data from Facebook. Your application caches data and receives updates, rather than polling Facebook’s servers. Caching data and using this API can improve the reliability of your application and decrease its load times.

Object

Instance for an achievement for a user.

A photo album

An application registered on Facebook Platform

A checkin made through Facebook Places or the Graph API.

A Comment on a Graph API object

A website domain within the Graph API

A Facebook event

A Facebook friend list

A Facebook group

Statistics about applications, pages, or domain.

A shared link

A message in a thread

A Facebook Note

An order object associated with Facebook Credits.

A Facebook Page

An individual photo within an album

An individual entry in a profile's feed

A question asked by a user, as represented in the Graph API.

An option allowed as an answer to a question.

A review for an application

A status message on a user's wall

A subscription to an application to get real-time updates for an Graph object type.

A message thread

A user profile.

An individual video



반응형

+ Recent posts