Facebook Graph API v2.0 retrieve friends with something in common - javascript

I am building an app that is intended to work as a directory of people who work for the same org, we all have Facebook in common so it seemed easy to make this to get us together. I have a question though, how can I get their info for testing before actually deploying the app? I was reading on Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app and noticed that it's not allowed easily or at all. Am I wrong?
Right now I have:
function getFriends() {
FB.api('/me/friends', function(response) {
console.log('Friends response', response);
if(response.data) {
$.each(response.data,function(index,friend) {
alert(friend.name + ' has id:' + friend.id);
});
} else {
console("Error!");
}
});
}
but I get the empty Array, is there anything I could do?

You have to ask for the user_friends permission.
This permission grants the app permission to read a list of this person's friends who also use your app. If any of this person's friends have chosen not to share their list of friends with your app, they will not show up in the list of friends for this person. Both people must have enable the user_friends permission enabled for a friend to show up in either friend list.

Related

Facebook Javascript API: '/me/albums' not working for other users

I am using the '/me/albums' for my website app in JavaScript. It returns the correct array when I use the app but not for other users.
Also, I have put the { scope: 'user_photos' } in FB.login(), but it doesn't ask the user for Photos permission when they log in.
For getting access_token, I'm using this:
accessToken = response.authResponse.accessToken;
Most permissions need to get reviewed before the can be used by everyone. Without review, they only work for users with a role in the App.
There should actually be a warning text whenever you try to login as an App Admin or Developer.
Official docs: https://developers.facebook.com/docs/facebook-login/review

FB JS SDK not picking up scope

This is the first question I've posted here, but have found stack more than useful in the past. I should also say I have searched for many hours, read many questions already asked and am still struggling.
So, I'm writing an FB app and my problem is with the JS SDK, I have set the permissions in the developer area of FB and have also specified the "scope" in FB.login, however on a clean (brand new account) version of FB, I am not being asked for the permissions I have specified, specifically publish_stream and photo_upload. Without this working properly, all images uploaded require "approving" by the user in their photo album, which is annoying and users are unlikely to do.
When I check the permissions on my developer account, I have the correct permissions, but cannot for the life of my understand why there is a difference between my two accounts.
Here is my login function with "scope" specified:
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
var access_token = FB.getAuthResponse()['accessToken'];
console.log('Access Token = '+ access_token);
testAPI();
} else {
// cancelled
}
}, {scope:'publish_stream,photo_upload'});
}
Any help would be appreciated and if I have missed any info, give me a nudge.
May be you are using the old SDK and that's why its not working. Earlier the property name for the permissions was not "scope", but "perms", so try out with "perms" and check if its working.

Explain the Facebook access_token

This whole Facebook access_token thing is driving me nuts. All I want to do is fetch a user's public Facebook posts.
It used to work by simply doing:
$.getJSON('http://graph.facebook.com/USERNAME/posts?limit=LIMIT&callback=?', function (posts) {
// Posts available in "posts" variable
});
But now I get the "access_token required" error.
Trust me; I've checked the docs, Googled all over and checked similar questions on SO but I'm really hoping there's a more straight forward way of doing this than what I've seen.
Do you really have to create a Facebook App (I don't even have an account), make the user "accept" the app and login etc for this to work?
With Twitter it's just as easy as it used to be with Facebook.
You really have to create a Facebook App (You need to have an account), make the user "accept" the app and login etc for this to work.
However you can search public posts of user (not a specific user) by facebook's public search api.
e.g.
https://graph.facebook.com/search?q=hello&type=post
This will search all posts with hello keyword in it.
Reference ( you need to have facebook account to see this page )
http://developers.facebook.com/docs/reference/api/
Edit (after seeing comments):
If you want to access public posts of your own page. You can pull it without any login from user (but you will need an access_token)
Generate an offline access_token from here,
http://developers.facebook.com/tools/explorer.
Then you can use that token to pull data . Thus no need of logging on by user.
https://graph.facebook.com/wesellwine/posts?access_token=<access_token from graph api explorer>

retrieve people/organization information from linked in

hi I am involved in a development of web app, where I have to retrieve information of people or organization from linkedin, dynamically.Suppose user A can search for Organization and user B can search for particular person.
I have gone the throough the linked in API's but was not able to figure it out how to implement it.
I am using Linkedin javascript API
Kindly help me
Using the LinkedIn API is a two-step process. First, get the user of your web app to authorize the app to access their LinkedIn information. This means setting up your app on LinkedIn as follows:
https://developer.linkedin.com/apis
Once you have that set-up, you can then query the LinkedIn API using JavaScript (I assume JavaScript is the language/method you want to use, as you tagged it).
You can adjust the results coming back, per the documentation, by using facets and parameters. For instance, to perform a people search that returns all user's named Barack and their profile headline and summary, you'd do something like:
IN.API.PeopleSearch()
.fields(["headline", "summary"])
.params({"first-name":"Barack"})
.result(function(result) {
alert JSON.stringify(result)
})
headline and summary are profile fields that you specify - you can change these to pull the information you need.
Update - including code to perform a company search.
To perform a Company Search using the JavaScript API, you'd use the IN.API.Raw() method:
IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url))")
.result( function(result) { /* handle result */ } )
.error( function(error) { /* handle error */ } );

How to post to user's wall when user is offline

I have just used the javascript sdk to publish to the wall when the user is online.
I am starting to like it. Now I want to post to wall when user is offline. I already have extended permissions from the user.
How can I post to user's wall when user is offline using javascript sdk.
here is my code:
function Publish(body){
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
I appreciate any help.
Thanks.
That's only possible when user permits you. In other words, you need offline_access extended permission from user and only after that you can do that.
I'm not 100% sure of this, but I don't believe you can accomplish this with only the JavaScript API.
Just getting the user to accept the permissions isn't enough - that doesn't make all your API calls "automagically" work. As mentioned in item #3 here, you are given an access_token that is to be used in future API calls on behalf of the user.
And so enters the problem with the offline_access permission. If using JavaScript only - where are you going to store the access token that grants offline access so that you may use it when the user is not at their computer?
If even you figured out how to store it and retrieve it for later use, I'm not sure if you can even use the JavaScript SDK to make API calls for a non-session user.
From my understanding, you only need 'publish_stream' permission - please check Do I need “offline_access” permission if I request publish_stream?

Categories

Resources