Can i load the private photos with my webapp from facebook users? - facebook

I have a website and use the login using facebook.
I want to do the following:
User comes to my web site - login with facebook - I read his facebook data and photography permits
For example:
{
"id": "1"
"name": "John English"
"first_name": "John",
"last_name": "English"
"link": "https://www.facebook.com/johnenglish"
"username": "johnenglish"
"gender": "male"
"locale": "en_US"
....
}
and
{
"id": "2"
"name": "John English2"
"first_name": "John",
"last_name": "English2"
"link": "https://www.facebook.com/johnenglish2"
"username": "johnenglish2"
"gender": "male"
"locale": "en_US"
....
}
Both users have a private photo. Can I load the private photos from user (id: 2) with my web application using javascript? Can you give me the example?
I've tried this:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/USER-ID(USER ID 2)/photos?access_token=' + accessToken, function(response) {
//A user access token is required to request this resource.
});
} else if (response.status === 'not_authorized') {
} else {
}
});
Error: A user access token is required to request this resource.

Have you requested the right permissions when you gained your access token? I don't know how to do it in JS, but you have to tell facebook, that you want you get access to the photos. As I do not work with JS, I request my access token via an URL (see Point 1 here: https://developers.facebook.com/docs/authentication/devices/). In the parameter "scope" you can add the permissions you want to have ( https://developers.facebook.com/docs/authentication/permissions/). Here, you add "&scope=user_photos" (without quotation marks) to the URL.

OK, now I understand your question.
I assume that you already found out the ID of the User 2. I am sorry but I can still not show you how to do it in JS. Though, it may help.
At first, I forgot one permission, you need friends_photos in scope, too.
You now call: http://graph.facebook.com/FRIEND_ID/albums/?access_token=ACCESS_TOKEN.
Type it into your browser, so that you know what I mean: You parse that output and find ids of the albums of your friend.
You get to that album via: http://graph.facebook.com/ALBUM_ID?access_token=ACCESS_TOKEN.
You will find an entry named cover_photo in your output.
Call: http://graph.facebook.com/COVER_PHOTO_ID?access_token=ACCESS_TOKEN and you get access to that photo.
You may now download it via http://graph.facebook.com/COVER_PHOTO_ID/picture?access_token=ACCESS_TOKEN.
Use the URL given in paging -> next to move on to the following photos. It is much easier to follow these steps with a picture in mind, consider that here.

Related

How to get instagram username from new facebook graph API

Looking at the new Instagram Graph API - there is no direct way to retrieve username once a user is logged in. Although it says in the official document that a call like
"https://graph.facebook.com/v3.2/17841405822304914?fields=biography%2Cid%2Cusername%2Cwebsite&access_token=EAACwX..."
should return the following:
{
"biography": "Dino data crunching app",
"id": "17841405822304914",
"username": "metricsaurus",
"website": "http://www.metricsaurus.com/"
}
This currently returns an error, and looks like there is no such option to get only username of an instagram business user.
If you are talking about fetching username of an instagram business account which is linked to your facebook page, you can use the below curl
curl -i -X GET "https://graph.facebook.com/v3.2/me/accounts?fields=instagram_business_account%7Busername%2Cname%2Cig_id%7D&access_token=<access_token>"
Please replace access_token with your user access token in the above curl.
Sample reponse which you will get for the above curl is as below :
{
"data": [
{
"instagram_business_account": {
"username": "<instagram user name>",
"name": "<instagram display name>",
"id": "<corresponding facebook graph id for instagram profile>",
"ig_id": <instagram profile id>
},
"id": "<facebook page id>"
}
],
"paging": {
"cursors": {
"before": "MTc2Njg1MTU2MTI1ODA1",
"after": "OTg3MzU1NzExNDUwMDg3"
}
}
}
If it helps to someone.. Now its better to do it like this GrapAPI v10.0
FB.api('/' + pageID + '?fields=instagram_business_account{id,name,username}',
function (response) {
// TODO: whatever you want
},
{ access_token: accessToken }
);
EDIT: I wouldn't do it this way anymore. Its very old code, I would wrap it somehow and I am not sure this still works..
I was able to solve this only by using the old api.
According to their documentation, although the old API is about to become deprecated, as of now, it is meant for small businesses or personal apps.
The new Instagram Graph API is "An API for accessing data in large- and medium-sized Instagram Business Accounts"
Looks like FB doensn't know it's way around.

Get user id and name from comment on Fan Page Wall

Since Facebook API update to v2.11, I cannot get User Id and Name from comments on FanPage Wall Post. Anyone can help/explain?
Usually I used this :
https://graph.facebook.com/[POST_ID_PAGE]/comments?order=reverse_chronological&access_token=[YOUR_ACCESS_TOKEN]
And the result just like :
{
"data": [
{
"created_time": values_date_TMZ,
"from": {
"name": USER_NAME,
"id": USER_ID
},
"message": THE_COMMENT,
"id": THE_COMMENT_ID
}
}
You need a Page Token now, to get user names - check out the changelog:
https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi
I assume you are using an App Token at the moment.
Edit: Of course it has to be a Page Token of the Page with the comment. And of course you need to manage the Page - else you would not even get a Page Token.

FaceBook API for friends count

There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count

Convert Facebook names to id numbers

I've noticed some difference in Facebook profiles :
Some of them have the following string format at browser nav bar :
http://facebook.com/john.smith
and the others look like this :
http://www.facebook.com/profile.php?id=100455*
Can someone explain why there is a difference ?
And more important is how can I convert those john.smith like names to id numbers ?
These are alias urls that Facebook offers its users (and pages) - its basically a vanity thing, both the id and the alias url will work the same way.
You can translate the alias (or username) by doing a lookup for that user using the Facebook Graph API. Simply make a GET request to https://graph.facebook.com/John for example - this will serve the following response:
{
"id": "779695190",
"name": "John Chan",
"first_name": "John",
"last_name": "Chan",
"link": "http://www.facebook.com/John",
"username": "John",
"gender": "male",
"locale": "en_US",
"updated_time": "2011-12-27T05:01:06+0000",
"type": "user"
}
response.id is what your interested in.
Test it out: http://developers.facebook.com/tools/explorer?method=GET&path=john
You're not really want to converting the ids to names but getting id by username which is possible by issuing request to Graph API:
GET https:/graph.facebook.com/john.smith?fields=id
Here is a JQuery based solution, where callback is an arbitrary function:
$.get("https://graph.facebook.com/" + name + "?fields=id", function(response){
if(response.error){
callback(false)
}else{
callback(response.id);
}
});

facebook graph can not get comments

After Search post from graph
https://graph.facebook.com/search?q=watermelon&type=post&fields=from,message,picture,link,name,caption,comments,description,created_time,id&token=XXXXXXXXXXXXX
here will return some data. In the third post:
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQDGoBK_lUeeMb5x&w=130&h=130&url=http\u00253A\u00252F\u00252Fi3.ytimg.com\u00252Fvi\u00252Fjo5GcYeh7XA\u00252Fdefault.jpg",
"link": "http://www.youtube.com/watch?v=jo5GcYeh7XA&feature=share",
"name": "Herbie Hancock \"Watermelon Man\"",
"caption": "www.youtube.com",
"description": "From the 1973 album \"Headhunters\" here's Herbie Hancock with \"Watermelon Man\" Sampled by Super Cat \" Dolly My Baby\" LL Cool J \"1-900-LL Cool J\" Shaquille O'N...",
"created_time": "2011-09-17T17:44:48+0000",
"id": "1665626783_235117223205324",
"comments": {
"data": [
{
"id": "1665626783_235117223205324_3043725",
"from": {
"name": "Alessio Mrbillyplus Frustaci",
"id": "1665626783"
},
"message": "La enne e la doppia effe aaaaaa",
"created_time": "2011-09-17T17:45:52+0000"
}
]
}
},
It is clearly that it has comments in it. So the PostID is 1665626783_235117223205324 and CommentID is 1665626783_235117223205324_3043725? But when I tried search a post or comments, the data return empty.
https://graph.facebook.com/1665626783_235117223205324?access_token=XXXXXXXXXXX//empty
https://graph.facebook.com/1665626783_235117223205324/comments?access_token=XXXXXXXXXXX//empty
https://api.facebook.com/method/fql.query?
callback=json&
query=SELECT%20comments%20FROM%20stream%20WHERE%20post_id%20%3D%20'1665626783_235117223205324'&access_token=XXXXXXXXXXXXXX //empty
What is the big problem?
There may be privacy settings in place which prevent the current user from seeing the posts or comments, where are those comments posted? Are you accessing them with an access_token from a user who can see the content?
As Mahima said, both of those calls should be working and i've tested equivalent calls with posts from my own news feed or page walls.
A call to /1665626783_235117223205324 for me returns false, which indicates i don't have permission to view the item.
This could also be a bug, but you'd need to have a very clear set of sample data to demonstrate the issue so it can be reproduced by Facebook
I tried with post id and comment id both as
http://graph.facebook.com/COMMENT_OR_POST_ID?access_token=APPLICATION_ACCESS_TOKEN
both are working ..
Make sure the access_token you are using is either of the application which you used for posting on a user's wal.. Or the access_token has sufficient read_stream and offline_access permission of the user ..