I luckly get some ununderstandable response when trying to get friendlist from a facebook account, this is what i got when console.log:
#v_3 { __wrapped=#v_3, __observableEvents={...}, name="v_3", more...}
The method FB.Data.query:toString is not officially supported by Facebook and access to it will soon be removed.
Here is my code for login and get user's friendlist member:
FB.init({ appId:'my_appid' });
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
$('#login').bind('click', function() {
FB.login(handleSessionResponse);
});
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});
// handle a session response from any of the auth related calls
function handleSessionResponse() {
FB.api('/me', function(response) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
console.log(response);
var friends = FB.Data.query('SELECT uid, flid FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=me())');
console.log(friends);
$('#user-info').html(response.id + ' - ' + response.name);
});
}
Anyone has exprienced the same issue?
Well, there is a much better way to get the friendlist of a user:
FB.api('me/friends', function(response) {
console.log(response);
}
If you really want to use FQL (which is not a good way in this case), it is explained how to use FQL with the JavaScript SDK in this thread: How can I execute a FQL query with Facebook Graph API
The correct FQL call to get the friends would be this one:
SELECT uid2 FROM friend WHERE uid1=me()
https://developers.facebook.com/docs/reference/fql/
Related
I cannot get cloud code to query a user when using a "standard" function...
If I define the function (as below), it works fine...
Parse.Cloud.define("findUser1", function(request, response){
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the objectId of the User I am looking for
query.first({
success: function(user){
response.success(user);
},
error: function(error) {
console.error(error);
response.error("An error occured while lookup the users objectid");
}
});
});
In this version, the function will be called, but the query within will not...
function findThisUser(theObject){
console.log("findThisUser has fired... " + theObject); //confirms "theObject" has been passed in
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the value of "theObject", just hard coded for testing
query.first({
success: function(users){
console.log("the user is... " + users);
// do needed functionality here
},
error: function(error) {
console.error(error);
}
});
};
Cloud code does not allow global variables, and I do not see how to pass in a variable to a "defined" function from another one. This is crucial as an outside function must be called to run the required tasks on the returned user. (This happens elsewhere and has to happen AFTER everything else does. This is the confirmation, and is supposed to be used by other functions as well) All potential information found to date has not helped, and the only experience I have in server side javascript is what I have cobbled together from other cloud code...
Any ideas on what I am missing?
This link may help, i had similar issue yesterday and after moving the code a little, and having the response.success(user); in my function all worked fine.
Parse Cloud Code retrieving a user with objectId
Not your exact issue - but this may help.
Heres is the code i use now:
Parse.Cloud.define("getUserById", function (request, response) {
//Example where an objectId is passed to a cloud function.
var id = request.params.objectId;
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("ObjectId", id);
query.first(
{
success: function(res) {
response.success(res);
},
error: function(err) {
response.error(err);
}
});
});
I am integrating facebook, twitter, github, linkedin using https://oauth.io/signin third party site.
I integrated facebook and was able to successfully get id, name, gender properties directly but am seeing difficulty in getting email address, location values.
In oauth.io site, I even added scope permissions for facebook
I am using the below code to get info of the logged in user.
OAuth.popup('facebook')
.done(function (result) {
res = result;
result.me().done(function (response) {
debugger;
console.log('me ' + response.name);
console.log('me ' + response.email);
});
})
.fail(function (error) {
alert('fail');
});
I even tried filtering the results only to give email, birthdate values using
OAuth.popup('facebook')
.done(function (result) {
res = result;
result.me(['email', 'birthdate', 'location']).done(function (response) {
debugger;
console.log('me ' + response.name);
console.log('me ' + response.email);
});
})
.fail(function (error) {
alert('fail');
});
But it just returned empty object.
Can some one let me know if I am missing something?
I was able to get the required fields for facebook using
result.get('/me?fields=name,email,gender,birthday').done(function (response) {
console.log('me ' + response.name);
});
But the same code is not working for twitter.
Still looking for an answer which works in a generic way for most of the apis
I am trying to send notification to user's friend using js sdk on facebook canvas app
but I get this in console
POST https://graph.facebook.com/16542203957691/notifications? 400 (OK) jquery.min.js:140
c.extend.ajax jquery.min.js:140
c.extend.post jquery.min.js:133
makePost ec2-34-41-111-91.ap-southwest-8.compute.amazonaws.com/:69
onclick
I am calling makePost function passing it the friend's profile Id as the argument, this is what I am trying
function makePost(personid){
var accesstoken = FB.getAuthResponse()['accessToken'];
var address = "https://graph.facebook.com/" + personid + "/notifications?";
var tempdata = {};
tempdata['access_token'] = accesstoken;
tempdata['href'] = "";
tempdata['template'] = "You have earned 5 credits, Click here to redeem";
jQuery.post(address, {json: JSON.stringify(tempdata)}, function(data){
console.log(data);
});
}
the person is not receiving the notification.
the problem was that its not the normal access token, here the access token will be a combination of your app id and app secret separated by "|" symbol.
also you need to send the data as an array and not as a json object.
So here is what the working code looks like.
function makePost(personid){
var address = "https://graph.facebook.com/" + personid + "/notifications";
var tempdata = {};
tempdata['access_token'] = appId + "|" + appSecret;
tempdata['href'] = "";
tempdata['template'] = "You have earned 5 credits, Click here to redeem";
jQuery.post(address, tempdata , function(data){
console.log(data);
});
}
PS: I am using Jquery Library to make the post request, So dont forget to include jquery.
What is the Ajax call that I should make to get gmail contacts using JavaScript? I already have the user OAuth Token which I got because the user signed up to my site using Google.
If you're using OAuth2 through JavaScript, you can use the Google Contacts API, but you'll need to get authorisation by sending the correct scope of permissions to Google when getting the access token, which is https://www.google.com/m8/feeds. (reference)
As you already know how to get the access token, it's as simple as calling the API with the correct query. To get all contacts for your user, it's as simple as making an asynchronous request to the API for the required info. For example, where {userEmail} is the user's email and {accessToken} is your access token, simply make a GET address to the following URI:
https://www.google.com/m8/feeds/contacts/{userEmail}/full?access_token={accessToken}&alt=json
A list of the types of queries you can send and their parameters are available here:
Google Contacts API
API Parameters
To get users' contacts using OAuth, first you need to specify the contact's scope in your request. If you're using ChromeExAuth, then you would write:
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url' : 'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize_url' : 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_url' : 'https://www.google.com/accounts/OAuthGetAccessToken',
'consumer_key' : 'anonymous',
'consumer_secret' : 'anonymous',
'scope' : 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.google.com/m8/feeds/',
'app_name' : 'MyApp'
});
The scope parameter above lists 3 scopes: the user's email, profile, and contacts (google.com/m8/feeds/contacts)
To get their contacts after the user authorizes the token, you would send a request like this:
var url = "http://www.google.com/m8/feeds/contacts/default/full";
oauth.sendSignedRequest(url, onContacts, {
'parameters' : {
'alt' : 'json',
'max-results' : 99999
}
});
And the callback for the request could look like this:
function onContacts(text, xhr) {
contacts = [];
var data = JSON.parse(text);
for (var i = 0, entry; entry = data.feed.entry[i]; i++) {
var contact = {
'name' : entry['title']['$t'],
'id' : entry['id']['$t'],
'emails' : []
};
if (entry['gd$email']) {
var emails = entry['gd$email'];
for (var j = 0, email; email = emails[j]; j++) {
contact['emails'].push(email['address']);
}
}
if (!contact['name']) {
contact['name'] = contact['emails'][0] || "<Unknown>";
}
contacts.push(contact);
}
};
To view the contacts array, you could just print on the console:
console.log(contacts);
You can checkout the Google OAuth tutorial here
I am trying to get a list of all friends of the current user using my Facebook application:
Here is my code for your reference:
var meID = <?php echo $data['user_id']; ?>;
var queryOnFriends = "SELECT uid, name, online_presence, status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + meID + ")";
var queryOnFriends1 = "SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=" + meID + ")";
var queryOnFriends2 = "SELECT uid2 FROM friend WHERE uid1 = me()";
var queryUserName = "SELECT name, uid FROM user WHERE uid={0}";
var query = FB.Data.query(queryOnFriends2, meID);
query.wait(function(rows){
alert("in callback");
document.getElementById('display').innerHTML =
'Your name is ' + rows[0].name;
});
Referring to my attempt using var queryUserName works fine, but all the others didn't work, even the simple queryOnFriends2 from the FQL examples.
The application asks for permissions correctly (read_friendlists, user_online_presence, friends_online_presence) and the FB JS SDK seems to initialize well, as querying for the user's own username (queryUserName) works, however, it does not even execute the callback function in the failing cases!
What am I doing wrong?
The difference between queryUserName and your other queries is that queryUserName contains a parameter, the {0}.
Your other queries are using me() instead, so they don't need a data parameter to be passed in.
You need to change this line:
var query = FB.Data.query(queryOnFriends2, meID);
to this:
var query = FB.Data.query(queryOnFriends2);
OK i got it now ... i used php to authorize my app ... but didn't authenticate as well! When using just the facebook jsSDK and initalize and then getStatus it does it all automaticly!
Then the queries worked!