How to get user friends list? - facebook

How can I get the user friends list of the logged in user? I authenticate the user and request the permission using the server redirect approach, for example:
Response.Redirect("https://www.facebook.com/dialog/oauth?" + "client_id=" + "12345678" + "&redirect_uri=" + "https://www.myserver.com:44316/FaceBookLoginRedirect.aspx" + "&scope=user_status,email,user_friends" + "&response_type=token");
FB doesn't show the user the permission request dialog and doesn't return the data such as email and user_friends
any idea?
Thx

Related

How to get Access and Refresh Token while allowing google app by user

I created a google app and in Google app marketplace sdk api filled all the required details and added scopes what i required. And created a webapp in chrome developer dashboard and submitted the app for testing. While first time installing the app from marketplace it get permission from user for the scopes i added in the google app marketplace sdk api. After i click allow it will just install the app. Here how can i retrieve Accesstoken and refresh token or Authorization code while user clicks allow?
I manually get Auth code using this api call:
""https://accounts.google.com/o/oauth2/auth?client_id=CLIENTID &redirect_uri=REDIRECT_URI&scope=email+profile+https://www.googleapis.com/auth/drive&response_type=code&access_type=offline""
In the redirected uri collects access and ref token using this api call:
String accessTokenUrl = "https://accounts.google.com/o/oauth2/token";
String accessTokenUrlParameters = "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri="
+ redirectUri + "&grant_type=authorization_code&code=" + code;
String accessToken = null;
String refreshToken = null;
try {
HttpClient hc = new HttpClient();
hc.setURL(accessTokenUrl);
hc.setHeader("Content-Length", "" + Integer.toString(accessTokenUrlParameters.getBytes().length));
hc.doPost("application/x-www-form-urlencoded; charset=UTF-8");
}
In this type i get both access and refresh tokens but while installing app for first time how do i get access token using that permissions and scopes. The consent screen while installing app has url like this.
https://accounts.google.com/o/oauth2/auth?client_id=1234567890-1od573nk87eq712l7suam1hu9upa8tm2.apps.googleusercontent.com&origin=https%3A%2F%2Fapis.google.com&authuser=0&login_hint=abcdefghijk#gmail.com&response_type=token&redirect_uri=postmessage&hl=en&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile
but it doesnt have redirect uri and all. How to get access token while allowing this consent screen.

facebook - how to get a new authorization code for an access token

I've read through the documentation and I don't understand how to get the new code, I was doing this to get a token to read the feed for a site I'm an admin on:
https://graph.facebook.com/oauth/access_token?client_id=" + sClientID + "&client_secret=" + sSecret + "&redirect_uri=" + sRedirectURI + "&code=" + sCode;
and then:
"https://graph.facebook.com/" + sUser + "/accounts?" + sToken;
To get the feed.
It's telling me:
{
"error": {
"message": "This authorization code has been used.",
"type": "OAuthException",
"code": 100
}
}
I know I need a new authorization code but cannot find the method to call to get one in the documentation. Alternatively, is there another way to get this feed?
STEP 1:
Please open your browser, type the following URL and hit.
https://www.facebook.com/v8.0/dialog/oauth?client_id={app_id}&redirect_uri={redirect_uri}
STEP 2:
Let's assume your {redirect_uri} = https://www.abc.co.in/.
Then you will receive new authorization code with the following format in the URL itself.
https://www.abc.co.in/?code={get_new_auth_code_here}
STEP 3:
Get the access token by the following URL with said new authorization code.
https://graph.facebook.com/oauth/access_token?client_id={app_id}&client_secret={app_secret}&grant_type=authorization_code&redirect_uri={redirect_uri}&code={newly_received_auth_code}
Cheer!
You may need to re-read the login documentation: https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/
You use the code one time only, and exchange it for an access_token - you then use the access token to make API calls on behalf of your users.
When the token expires (in approx 60 days) or the next time the user comes back to your app, you send the user through the login flow again, get a new code, and exchange that for a new token which will be valid for up to 60 days

Facebook Graph API get USER token instead of APP token (phonegap)

I'm trying to implement facebook connect in Adobe PhoneGap through the Graph API but apparently I'm getting back an "App" token instead of a "User" token. This causes for my app to disallow any additional users connecting onto it, which is not the point of course.
I have notice this as no matter what user I use for logging in, the access_token returned is always the same.
I'm using the following URL to authenticate:
var authorize_url = "https://graph.facebook.com/oauth/authorize?";
authorize_url += "client_id=" + fb_clientid;
authorize_url += "&redirect_uri=" + fb_redirect_uri;
authorize_url += "&display=" + fb_display;
authorize_url += "&scope=publish_stream"
And to get the authorisation token:
https://graph.facebook.com/oauth/access_token?client_id='+fb_clientid+'&client_secret='+fb_secret+'&code='+fbCode+'&redirect_uri=http://www.facebook.com/connect/login_success.html'
I presume the problem lies with the second url (secret being passed indicates it's an app token) but then how do I get the user token?
Use the Facebook Connect plugin, instead of crafting the login procedure manually. It provides better usability as it is integrated with the Facebook native application or the iOS 6 Facebook functionality.

Obtaining a facebook access token to use with facepy

I am doing a project for school where I have to get all of my friend data, and the friend data of some of my friends, from facebook in order to make a graph of it. To do this I am planning on using facepy, but in order to do that I need an access token. My question is how do I obtain this access token?
facepy doesn't natively include a way for the OAuth process
https://github.com/jgorset/facepy/issues/22
You will need to use your own method or external library for the user to be guided via a web application.
For example using web.py and facepy to get me/posts with read_stream permission
import web
from facepy import GraphAPI
from urlparse import parse_qs
url = ('/', 'index')
app_id = "YOUR_APP_ID"
app_secret = "APP_SECRET"
post_login_url = "http://0.0.0.0:8080/"
user_data = web.input(code=None)
if not user_data.code:
dialog_url = ( "http://www.facebook.com/dialog/oauth?" +
"client_id=" + app_id +
"&redirect_uri=" + post_login_url +
"&scope=read_stream" )
return "<script>top.location.href='" + dialog_url + "'</script>"
else:
graph = GraphAPI()
response = graph.get(
path='oauth/access_token',
client_id=app_id,
client_secret=app_secret,
redirect_uri=post_login_url,
code=code
)
data = parse_qs(response)
graph = GraphAPI(data['access_token'][0])
graph.get('me/posts')
For more info see
* Facebook API - User Posts: http://developers.facebook.com/docs/reference/api/user/#posts
* Publish a Facebook Photo in Python – The Basic Sauce: http://philippeharewood.com/facebook/publish-a-facebook-photo-in-python-the-basic-sauce/
* Facebook and Python – The Basic Sauce: http://philippeharewood.com/facebook/facebook-and-python-the-basic-sauce/
Basically, you just have to log in.
If you go to the graph API overview page It will ask you to log in with your own facebook account. After that all of the links on the page will have an access token with permission to see whatever you can see.

How to publish to a facebook wall as a different person

I maintain an asp.net website and have a requirement to publish to the businesses facebook wall as the business.
We set up a facebook app to do so.
So what happens is after a user clicks a button on the website the program calls facebook with scope=publish_stream,offline_access,manage_pages parameter
Facebook returns a code
We call facebook again with something that looks like this
string.Concat("https://graph.facebook.com/oauth/access_token?client_id=" + facebookPostClientId,
"&redirect_uri=" + "blah.aspx", "&client_secret=" + facebookPostSecret, "&code=" + code )
Facebook returns an access token.
We then call facebook to get all the accounts with something like this:
https://graph.facebook.com/" + facebook_user_id + "/accounts?access_token=" + accessToken;
We then loop throught the accounts until we find the correct one and call facebook again with something like
https://graph.facebook.com/" + userName + "/feed?&access_token=" + accessToken + "&picture=" + picture + "&name=" + "Studentcard - Deal" + "&link=" + link + "&message=" + message + "&caption=" + caption + "&from=" + userName + "&to=" + userName;
It works after a fashion. IF the owner of the business who created the facebook app is logged on to facebook, then the processing works.
If anyone else is logged on then it doesn't.
The reason being that the bit where we call facebook to get all th accounts only works when the business owner is logged on to facebook.
I tried inserting the business owners facebook id inbto the code instead off the logged on users, but it doesn't work.
So what do I do? Is this the wrong way to go about this?
I realise this maybe a bit long winded, but I am new to facebook and am providing as much information as I think necessary.
Thanks in advance
Niall
The reason being that the bit where we call facebook to get all th accounts only works when the business owner is logged on to facebook.
Separate this part of the process. Get all the accounts, and then cache them in your database. Whenever you fail to get the accounts, just use the cached information and proceed normally (otherwise update the DB and proceed normally).