Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Submitted by:
SCOPE
OBJECT IDs
Each node has a uniqueIDwhich is used to access it via the Graph API.
Here's how we'd use the ID to make a request for:
a node:
GET graph.facebook.com
/{node-id}
an edge:
GET graph.facebook.com
/{node-id}/{edge-name}
PUBLISIHING A POST
We can generally publish to APIs by
making HTTP POST requests with
parameters to:
a node:
POST graph.facebook.com
/{node-id}
an edge:
POST graph.facebook.com
/{node-id}/{edge-name}
1. GENERATE ACCESSS
TOKEN
1. Open
developers.facebook.com/tools/explorer
Output
READING DATA
All nodes and edges in the Graph
API can be read simply with an
HTTPGETrequest to the relevant
endpoint.
For example, if we wanted to
retrieve information about the
current users photos, we would
make an HTTPGET request as
below:
GET graph.facebook.com/me/photos
OUTPUT
The response we receive varies
based on the node or edge that we
are reading, but it takes the
following general form:
{
"fieldname": {field-value},
....
}
CHOOSING FIELDS
By default, not all the fields are
returned in a node or edge when
making a query.
fields (or edges) can be chosen with
the help of returned with the
"fields" query parameter.
This will help to make API calls more
efficient and fast.
CHOOSING FIELDS...
Example:
GETgraph.facebook.com/me?
fields=id,name,picture
This will return only the id, name , and
picture in the users profile.
URL LOOKUP
We can simply provide an equivalent
Graph API request as a URL in the
address bar of a web browser.
SYNTAX
https://graph.facebook.com/v2.X/{node-id}?
fields={edge} &
access_token=[ACCESS TOKEN]
OUTPUT
{
"friends": {
"data": [
"id": "546362948"
},
"id": "10152694647908054"
},
"id": "10153131300151705"
},
"id": "820988834"
},
"id": "842963235"
},
"id": "1290351452"
},
OUTPUT(con..)
{
"name": "Parikshit Gautam",
"id": "1474586213"
},
{
"name": "Nishant Kakar",
"id": "1521727101"
},
{
"name": "Ankit Goel",
"id": "10204943353055381"
},
{
"name": "Rajat Goyal",
"id": "1720944185"
},
{
"name": "Amit Grover",
"id": "840594279287740"
},
{
"name": "Shalabh Tripathi",
"id": "1007504115967128"
},
OUTPUT(con..)
{
"name": "Abu Zafar Nadeem",
"id": "801283979928027"
},
{
"name": "Mudasir Wani",
"id": "943744019015779"
},
{
"name": "Akmal Raza",
"id": "751351998311011"
}
],
"paging": {
"next": "https://graph.facebook.com/v2.0/4177943384506/friends?
access_token=CAACEdEose0cBABjaudZBChN3RWO2PO4jpejBcaf6AAAqTeHZAAGjL8c0BMlNRDNv6LQ4nydiC
TlZAAU1mYfjAVOR2tw5HPVoYS0zbxxMEuXenfBKNkuzmXqKZA3MUskHvHQX7O9q1440RWixychNsi23ZCWZC
dizWJwu3rmrPuYihtk8Het2UplF22xfbXT0p5X21nvzFPuK6vAZARbfFIt&limit=5000&offset=5000&__after_id=e
nc_AdAM31X4AeWZAvXdNqYSXpFZCMRvPO2ZBL1jAZAROQotsU0sLKIky7GIpK1a3ixkNlNXR7VphYBrPDhVYKC
jfpZAME8ZAm"
},
"summary": {
"total_count": 1083
}
},
"id": "4177943384506"
}/
OUTPUT...
This doesnt display all of the friends
as in the output because total_count
is equal to 1083.
This actually displays only the
friends who have created an app on
Facebook.
PUBLISHING A POST
Before publishing a post on
facebook using Graph API post
request, we need publishing
permissions.
For that publish_actionspermission
is selected from Get Access Token
feature.
PUBLISH A POST
Click on the button that says "GET"
on it.
Choose "POST" from the dropdown
selector that appears.
Enterme/feedin the path field.
PUBLISH A POST...
PUBLISH A POST...
click "Add a Field".
In the new fields that appear, we
putmessageas the "name",
andHello, World!as the value. It
should look something like this:
PUBLISH A POST...
UPDATING
All Graph API updating is done
simply with an HTTP POSTrequest
to the relevant node with any
updated parameters included:
POST graph.facebook.com/{node-id}?
{updated-field}={newvalue}&
access_token={access-token}
UPDATING A COMMENT
We can edit a comment by using the
following endpoint:
POST /v2.0/{comment-id}
message=This+is+a+test+comment
UPDATING A COMMENT...
An example is shown here
EXTRACTING FRIEND
LIST
IDEA 1:
Extracting all friends by the
following request is not possible:
https://graph.facebook.com/v2.0/me?
fields=friends&access_token=[ACCESS
TOKEN]
EXTRACTING FRIEND
LIST...
Following is the request well make to extract
all the friends who have been active in
activities such as liking and commenting on
posts, albums and photos:
https://graph.facebook.com/me?
fields=feed.limit(1000).
fields(likes.fields(id,name))
&photos.limit(200).
fields(likes.fields(id,name))
&albums(10).
fields(likes.fields(id,name))
&access_token=[ACESS TOKEN]
IDEA 2:
Another idea we have is using the
URL class of java.net package to
get the content of the web page
displaying the response of the
above Graph API Request. And then
we can parse the response.
PSEUDOCODE
Get the responses of Graph API Explorer
using URL class in a string.
Parse the string till its end is reached.
Wherever we find the token as keyword id,
we store the next token ie. the value of id.
If the next token is the keyword name, then
definitely the next token is the value of name ie.
the name corresponding to the id we just
extracted.
Else, discard the id and continue with the next
iteration. This means the id we just extracted may
be the id of a post, photo album or comment etc.
as we know every node has an id associated with
itself.
TIME COMPLEXITY: O (n
logn)
Sorting the data before removing duplicate
entries makes the extraction extra ordinarily
fast.
this algorithm could have been highly
inefficient with time complexity O (n2). And
hence for approx. 1000 records O (n 2) would
mean 1000000 (1 million) traversals of the
data that must not have been feasible.
So, Merge Sort is chosen. [O (n logn)]
[only 3000 traversals for 1000 records vs.
1 million traversals for 1000 records]
USER INTERFACE
The program on running asks for the
user Access Token.
USER INTERFACE...
The user enters the access token that he
gets from
developers.facebook.com/tools/explorer
and clicks on Submit button.
USER INTERFACE...
The friend list in a tabular format
opens up. Which is a scrollable list.
We were able to recover 520 friends
out of 1084 friends in this test.
CONCLUSION
LEARNING OUTCOME: How to use Graph API
Explorer to get data in and out of Facebook.
Extract a feature (friend list) by programming.
Applications in the field of Data Mining.
Target Marketing: Categorization of the users
on the basis of certain interests and then
choosing target customers accordingly.
One area could be Healthcare and Insurance. By
extracting the birth date field of every user, we could
find their age and classify them under a certain age
group.
CONCLUSION
Opinion Mining a.k.a. Sentiment
Analysis: This involves building a system to
collect and categorize opinions about a
product.Automated opinion mining often
uses machine learning, a type of artificial
intelligence (AI), tomine textfor sentiment.
So attributes like number of shares and
number of likes could be used to measure
the popularity of a news or post. It involves
the use of Natural Language Processing.
REFERENCES
https://en.wikipedia.org/wiki/Faceboo
k_Platform#History
https://en.wikipedia.org/wiki/Facebook
_features
https://www.facebook.com/help/863
171203733904
https://developers.facebook.com/docs
/graph-api/overview
https://docs.oracle.com/javase/7/docs
/api/java/net/URL.html
THANK YOU.