Can not retrieving friends information using Facebook Graph API - facebook

Here is some testing code:
<script>
var movieList = new Array();
var friendList=" ";
var friendCount = 0;
function get_friend_likes() {
FB.api('/me/friends', function(response) {
friendCount = response.data.length;
for( i=0; i<response.data.length; i++) {
friendId = response.data[i].id;
friendList=friendList+(response.data[i].name)+'<br/>';//store names
FB.api('/'+friendId+'/movies', function(result) {
movieList = movieList.concat(result.data); //fetch data to the pool
friendCount--;
document.getElementById('test').innerHTML = friendCount
+ " friends to go ... ";
});//end_FB.api
} //end_for
});//end_FB.api
}
</script>
The problem is: I can get the friends' names and ids successfully with the outer FB.api call, but I can't get '/movies' information in the inner FB.api call. The returned data is empty.
Any insights on this? Thanks a lot!!

According to the User object api documentation you need the "user_likes" permission to get /me/movies and "friends_likes" permission to get friendId/movies.
Have you asked for these permissions?
Not sure how you authenticate your users, but you can do it with the javascript sdk as well:
FB.login(callbackFunction, { scope: "user_likes,friends_likes" });

Related

Facebook api not returning friends contact info

In my contacts manager app, I need to have an option to import contacts from facebook. Im using hello.js This is the function
function getFriends(network, path){
var list = document.getElementById('list');
list.innerHTML = '';
// login
hello.login( network, {scope:'friends'}, function(auth){
if(!auth||auth.error){
console.log("Signin aborted");
return;
}
// Get the friends
// using path, me/friends or me/contacts
hello( network ).api( path , function responseHandler(r){
for(var i=0;i<r.data.length;i++){
var o = r.data[i];
var li = document.createElement('li');
var ph = "";
if(o.gd$phoneNumber != undefined)
{
for (var j = 0; j <= o.gd$phoneNumber.length; j++ ) {
if(o.gd$phoneNumber[j] != undefined)
{
//console.log(o.gd$phoneNumber[j].$t);
ph += o.gd$phoneNumber[j].$t +'<br>';
}
};
}
li.innerHTML = o.name + (o.thumbnail?" <img src="+o.thumbnail+" />":'') +' Phone : '+ph;
list.appendChild(li);
};
});
});
}
The function is invoked by getFriends('facebook','me/friends') .This only returns the count of friends like this
{
"data": [
],
"summary": {
"total_count": 1076
}
}
but by using getFriends('facebook','me/taggable_friends'), I'm getting the name and image of the friends but not any email id or contact number.
Can anyone figure out the issue ?
/me/taggable_friends is ONLY for getting tagging tokens (you don´t get User IDs), and ONLY for tagging your friends (in status posts, for example).
/me/friends only returns friends who authorized your App too, that´s intentional. Users who don´t use your App don´t show up for privacy reasons.
That being said, even if you would be able to get ALL friends, you can´t get any details like email and especially not a contact number. You can´t even get the phone number from the authorized User.
Detailed information can be found in the changelog: https://developers.facebook.com/docs/apps/changelog

Getting Facebook Interests graph api call

I am trying to get the users liked Facebook pages, here is my code:
exports.checkUserInterests = function (fbaccountID,fbModule) {
var facebookModule = fbModule;
;
//code to get the list of facebook likes for any given user
facebookModule.requestWithGraphPath('me/interests', {}, 'GET', function(e) {
if (e.success) {
alert(e.result);
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response');
}
});
};
My Permissions is set as following:
//set permissions for graph api
var permissions = ['user_friends', 'user_interests', 'user_birthday', 'user_photos', 'basic_info'];
I an returning an empty json array, is my request correct?
Thanks
I use a different call to get the Facebook Likes of a user, maybe thats the problem.
For example, if I want to know if the user likes a page with id: xxxxx, I do a GET call to "me/likes/xxxxxx" and see if the result is true.
For this to work, you should have the permissions to user_likes.

How should I retrieve original pictures included with the Facebook posts?

My application uses the Facebook Javascript SDK to add wall posts to the feed of a community's page, and to retrieve them again. Pictures included with the posts are processed and placed somewhere on the Facebook servers.
When these posts are retrieved the links to the pictures turn out to be links pointing to the fbcdn.net server.
Is there a way to access the original links?
Update:
Here is my code posting a post:
// The "params" variable contains a field called "picture"
// (which is a link pointing to my picture)
FB.addWallPost = function (params, pageId, token, complete) {
var fbApiParams = {
access_token: token
};
$.extend(fbApiParams, params);
FB.api(pageId + '/feed', 'post', fbApiParams, function (response) {
// FB.apiCallDone is a function checking if there's any positive response
if (FB.apiCallDone(response)) {
complete(response.id);
}
else {
complete(null);
}
});
}
And these lines retrieve the posts:
FB.getWallPosts = function (wallPostsIds, token, complete) {
if (wallPostsIds && wallPostsIds != null && wallPostsIds.length) {
var wallPostsIdsStr = wallPostsIds.join(',');
var fbApiParams = {
ids: wallPostsIdsStr,
access_token: token
};
FB.api('/', fbApiParams, function (response) {
if (FB.apiCallDone(response)) {
var wallPosts = dictElemsToArr(response);
complete(wallPosts);
}
else {
complete([]);
}
});
}
else {
complete([]);
}
}
If you're posting pictures to Facebook, they will be stored locally by Facebook.
It is up to your application to store the path of the original images if your application requires this information.

DotNetOpenAuth Get Facebook Email Address

I have the following code where its grabbing First/Last name. I realize that email is an extended permission, but what would I need to modify to request extended permissions?
How do I get the email of an authenticated Facebook user through the DotNetOpenAuth?
fbClient = new FacebookClient
{
ClientIdentifier = ConfigurationManager.AppSettings["facebookAppID"],
ClientSecret = ConfigurationManager.AppSettings["facebookAppSecret"],
};
IAuthorizationState authorization = fbClient.ProcessUserAuthorization();
if (authorization == null)
{
// Kick off authorization request
fbClient.RequestUserAuthorization();
}
else
{
var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var graph = FacebookGraph.Deserialize(responseStream);
// unique id for facebook based on their ID
FormsAuthentication.SetAuthCookie("fb-" + graph.Id, true);
return RedirectToAction("Index", "Admin");
}
}
}
return View("LogOn");
Add the following bits:
var scope = new List<string>();
scope.Add("email");
fbClient.RequestUserAuthorization(scope);
If you are using VS2012 built in oauth providers you just need to update your oauth package. See the last post on the following link: http://forums.asp.net/t/1847724.aspx/1. The only email I can't retrieve is MS Live. Currently I use facebook, google, and yahoo.

FaceBook API: Get the Request Object for a request Id - logged into the account that sent the request. Using the "Requests Dialog" API

I am using the "Requests Dialog" to create Facebook requests. Inorder to get the user that the requests were sent to I need to access the Request object using the graph API. I have tried most of the permissions settings that seemed appropriate (read_requests and user_about_me) to get the request object, but instead I get a false in the response. Am I using the wrong permissions?
I am able to access the request object using the graph API from the account that the request was sent to.
http://developers.facebook.com/docs/reference/dialogs/requests/
Return Data - A comma-separated list
of the request_ids that were created.
To learn who the requests were sent
to, you should loop through the
information for each request object
identified by a request id.
I've been asking myself this question a while ago:
How to retrieve all the requests sent by me?
The answer: you can't!
You have two options:
Store the request_id returned when the user sent the request, so you can later access them and get the data you need
Knowing the receiver!
Proof of the above, you can check the friend_request table. The indexable field is the uid_to field!
This is if you want it in know Iframe mode as you don't need Iframe mode any more
function sendRequest() {
FB.ui({
method: 'apprequests',
title: 'Invite friends to join you',
message: 'Come play with me.'
},
function (res) {
if (res && res.request_ids) {
var requests = res.request_ids.join(',');
$.post('FBRequest.ashx',
{ request_ids: requests },
function (resp) { });
}
});
return false;
}
If you want to find out the user ids of the people you just sent a request to. Then this code is what you need:
var request = {
message: msg,
method: 'apprequests',
title: 'Select some of your friends'
};
FB.ui(request, function (data) {
if (data && data.request_ids) {
// Get the uid of the person(s) who was/were invited
var uids = new Array();
FB.api("/?ids=" + data.request_ids.join(), function(data2) {
for (i = 0; i<data.request_ids.length; i++) {
uids[i] = data2[data.request_ids[i]]['to']['id'];
}
# do something with uids here
});
}
});
Don't know if this helps, but here's how I handle it.
Javascript:
function sendRequest() {
FB.ui({
display: 'iframe',
method: 'apprequests',
title: 'Invite friends to join you',
message: 'Come play with me.'
},
function (res) {
if (res && res.request_ids) {
var requests = res.request_ids.join(',');
$.post('FBRequest.ashx',
{ request_ids: requests },
function (resp) { });
}
});
return false;
}
Server side (FBRequest.ashx):
// get operation and data
var ids = HttpContext.Current.Request["request_ids"];
// if we have data
if(ids != null) {
// make batch graph request for request details
var requestIds = ids.Split(',').Select(i => long.Parse(i)).ToList();
var fbApp = new FacebookWebClient([AppId],[AppSecret]);
dynamic parameters = new ExpandoObject();
parameters.ids = ids;
dynamic requests = fbApp.Get(parameters);
// cycle through graph results and do stuff
dynamic req = null;
for(int i=0;i<requestIds.Count;i++) {
try {
req = requests[requestIds[i].ToString()];
// do stuff with request, save to DB, etc.
} catch (Exception ex) {
// error in finding request, continue...
}
}
}
You can access the list of user id's as part of the return data
FB.ui({
method: 'apprequest',
message: 'Use this thing',
}, function(result){
//a list of ids are in here
result.to;
});