Created
March 3, 2012 03:39
-
-
Save mharsch/1964199 to your computer and use it in GitHub Desktop.
create a pair of facebook test users and make them friends
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var qs = require('querystring'); | |
var request = require('request'); | |
var fbapp = { | |
id: '<your fb app id>', | |
secret: '<your fb app secret>' | |
}; | |
var fb_perm = 'email,user_birthday,user_interests,user_location,friends_birthday,friends_interests,friends_location,publish_stream,offline_access,sms'; | |
var u1_name = 'John Doe'; | |
var u2_name = 'Jane Doe'; | |
var app_login_url = 'https://graph.facebook.com/oauth/access_token' | |
var app_login_qs = { | |
client_id: fbapp.id, | |
client_secret: fbapp.secret, | |
grant_type: 'client_credentials' | |
}; | |
// Obtain App Access Token | |
request.get({url: app_login_url, qs:app_login_qs}, function (e, r, body) { | |
if (!e && r.statusCode == 200) { | |
var app_token = qs.parse(body).access_token; | |
var create_user_url = 'https://graph.facebook.com/' + fbapp.id + '/accounts/test-users' | |
var create_user_qs = { | |
installed: 'true', | |
name: u1_name, | |
permissions: fb_perm, | |
access_token: app_token | |
} | |
// Create 1st User | |
request.post({url: create_user_url, qs: create_user_qs, json: true}, function (e, r, body) { | |
if (!e && r.statusCode == 200) { | |
console.log(body); | |
var u1id = body.id; | |
var u1at = body.access_token; | |
// Create 2nd User | |
create_user_qs.name = u2_name; | |
request.post({url: create_user_url, qs: create_user_qs, json: true}, function (e, r, body) { | |
if (!e && r.statusCode == 200) { | |
console.log(body); | |
var u2id = body.id; | |
var u2at = body.access_token; | |
// Friend Request | |
var friend_req_url = 'https://graph.facebook.com/' + u1id + '/friends/' + u2id; | |
var friend_qs = { access_token: u1at }; | |
request.post({url: friend_req_url, qs: friend_qs}, function (e, r, body) { | |
if (!e && r.statusCode == 200) { | |
console.log('friend request sent'); | |
// Accept Friend Request | |
friend_req_url = 'https://graph.facebook.com/' + u2id + '/friends/' + u1id; | |
friend_qs.access_token = u2at; | |
request.post({url: friend_req_url, qs: friend_qs}, function (e, r, body) { | |
if (!e && r.statusCode == 200) { | |
console.log('friend request accepted'); | |
console.log('friends are ready'); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment