Sei sulla pagina 1di 52

FEATURE EXTRACTION FROM

FACEBOOK

Submitted by:

Saurabh Bhatia (13-MCA-41)


Abu Zafar Nadeem (13-MCA-01)
Akmal Raza (13-MCA-02)

SCOPE

GRAPH API EXPLORER

GRAPH API EXPLORER


The primary way to get data in and
out of Facebook's platform.
Low-level HTTP-based API
We can use it to query data, post
new stories, manage ads, upload
photos and a variety of other tasks
that an app might need to do.

GRAPH API EXPLORER...


Named after the idea of a 'social
graph' - a representation of the
information on Facebook composed
of:
nodes- basically "things" such as a
User, a Photo, a Page, a Comment.
edges- the connections between those
"things", such as a Page's Photos, or a
Photo's Comments
fields- info about those "things", such
as a person's birthday, or the name of a
Page

GRAPH API EXPLORER...


HTTP based
Hence, works with any language
that has an HTTP library, such as
cURL, urllib.
Example: Java has a java.net
package containing URL class.
(We use Java)

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}

THE ACCESS TOKEN


Most requests to the Graph API
needan access tokenas a
parameter.
An access token is unique to the
combination of a logged in user or
page and the Facebook App that
makes the request.

THE ACCESS TOKEN...


Thus, a token provides temporary
and secure access to Facebook.
We can get an access token
fromthe Graph API Explorer.
A token may or may not have an
expiry time depending on whether
they are short-term (1-2 hour) or
long-term (60 days) tokens.

THE ACCESS TOKEN...


After the expiry of a short-term
token, We need to re-authenticate
the user and get a new token.

USING GRAPH API EXPLORER

1. GENERATE ACCESSS
TOKEN

1. Open
developers.facebook.com/tools/explorer

2. Click on theGet Tokenbutton in the top


right of the Explorer and choose the
optionGet User Access Token. Dont
check any box.

3. We'll see a Facebook Login Dialog, click


**OK" here to proceed.

Making First Request


Read' request
In the text field beside the "GET" dropdown
button (we'll call this the path field), delete
the existing text and type in 'me':
Press the "Submit" button. What appears
here for us is determined by the privacy
settings of our profile, but there should at
least be some basic fields:

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]

making a Graph API GET request using


URL Lookup to get friends.
https://graph.facebook.com/v2.0/me?
fields=friends&access_token=[ACCESS TOKEN]

OUTPUT
{

"friends": {

"data": [

"name": "Nikhil Gupta",

"id": "546362948"

},

"name": "Ankit Sharma",

"id": "10152694647908054"

},

"name": "Dishant Malik",

"id": "10153131300151705"

},

"name": "Shantanu Barua",

"id": "820988834"

},

"name": "Ankit Sharma",

"id": "842963235"

},

"name": "Anurag Kalia",

"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_actions needs to be checked

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

An example is shown here

UPDATING A COMMENT...
An example is shown here

Open the Graph API Explorer and use


following code.
POST /v2.0/
10201103343743364_1020110380423
4876?
message="This is a test message"
&access_token=[ACCESS TOKEN]

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]

Try and develop a new technique


So that at least 50% friends
(approximately) can be extracted.

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.

The (id, name) pairs we have just extracted


can have duplicate entries. As we need unique
entries, we need to remove duplicates.
a. So we first sort the (id, name) pairs by name
using merge sort and associate with each entry a
Boolean attribute duplicate.
b. Next we move iteratively from the start and
compare adjacent ids.
c. The first time an id is found, the (id, name) pair is
not duplicate and hence its duplicate field is
marked as FALSE. Now all the subsequent entries
having this id value are duplicate.
d. Go to step c) and repeat the process until all the
records are scanned.

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.

Potrebbero piacerti anche