Through APIs: How to get publicly sharable link of a Facebook Album that is locked or set to private? - facebook

Is there a way to get the public link of a Facebook Album through the Facebook API (graph/fql) that can be shared with those who are not on Facebook?
This Album is not publicly accessible. It is restricted by the share permissions on the album set by the user. But I am looking for a way to generate the public link of this restricted album so whoever is sent this link can view the album unconditionally.
I know this is possible through the Share Album feature on the Facebook website through the Share Dialog: You can send this album to friends or relatives by giving them a link.
I couldn't find a way to to this in the Graph API.
EDIT: I'm talking about the public link that is available through this feature on facebook: facebook.com/help/124590517619792

You didn't provide an example or test case, nor any API code to work with. I'll use the following links for Facebook User Name Hostess as an example (long live Twinkies!).:
Main: https://www.facebook.com/Hostess
Photo Album: https://www.facebook.com/Hostess/photos_albums
First, we will need the Facebook User Number.
You can perform a GET request or type this into the browser:
Facebook User Info: http://graph.facebook.com/Hostess
To continue with this example, we will use the Facebook Number provided by the previous step:
Facebook ID: 145369525544570
Is there a way to get the public link of a Facebook Album through the
Facebook API (graph/fql) that can be shared with those who are not on
Facebook?
Yes there's a way! This link will provide you with json results for all albums, in this case 6:
Facebook Albums via json: http://graph.facebook.com/145369525544570/albums
To limit the returned results, you can use ?limit=1 (where 1 is the amount of albums returned):
Facebook Album (1) via json: http://graph.facebook.com/145369525544570/albums?limit=1
This Album is not publicly accessible. It is restricted by the share
permissions on the album set by the user. But I am looking for a way
to generate the public link of this restricted album so whoever is
sent this link can view the album unconditionally.
Your out of luck and there isn't a way. However, you don't have to be a Facebook Member to view the images in the Album. Using the json data from the previous step works when the Album is made public. Just use a simple GET request:
jsFiddle DEMO: Facebook Albums Links from Facebook ID
// Console log messages are provided, activate your browsers console.
$.ajax({
url: 'http://graph.facebook.com/145369525544570/albums',
dataType: "json",
success: function(yourVar) {
// Make sure the request, 1 json object, was returned.
if (yourVar) {
console.log('This is the jQuery Object received. Click on it to explore contents');
console.log(yourVar);
// This will parse the Objects received in 'data' variable.
// Having said that, it's coincidental the data the wrapped in a 'data' name.
$(yourVar.data).each(function(index) {
// Only process Objects that have valid Album links.
// Having said that, only Photo Albums are returned in initial data, not Video Albums.
if(this.link){
// Display in console the jQuery zero indexed number
console.info('Album Index object: ' + index);
//
// Display in HTML via append, the same information.
$('body').append('<b>Album Index Object: </b>' + index + '<br />');
// Display in console the Album Names available
console.info('Name: ' + this.name);
//
// Display in HTML via append, the same information.
$('body').append('<b>Name: </b>' + this.name + '<br />');
// Display in console the Album Name Url;
console.log('Url: ' + this.link);
//
// Display in HTML via append, the same information.
$('body').append('<b>Url: </b>' + this.link + '<br />');
// Display in console dashed lines before next item is shown.
console.log('-------');
//
// Display in HTML via append, the same information.
$('body').append('<hr><br /><br />');
}
});
} else {
console.log('Was data expected? Check your jQuery or JavaScript for errors.');
}
}
});
// Power-Tip!
// You can also use .ajax() with a YQL Rest Query url.
// See YQL Console with Rest Statement at:
// http://developer.yahoo.com/yql/console/?q=SELECT%20data.link%20FROM%20json%20WHERE%20url%3D%22https%3A%2F%2Fgraph.facebook.com%2F145369525544570%2Falbums%22&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
// As seen there, the data.link is providing just the links.
// Change data.link to * to see all data nodes available in json tree.
// That being said, your .ajax() url for above is at the bottom: The Rest Query.

In Detail: Why it can't be done. (otherwise it's a security issue!!!)
Facebook Settings for Photos and Albums:
When I share something, how do I choose who can see it?
The above Facebook documentation states that if a Album is set to Private via Only Me, then it will only be available to you, even though you may have a shareable link for it.
To demonstrate that the Album/Photos is indeed locked and not shareable, here is an actual live test using Yahoo! Query Language to perform a request on a locked photo album:
Feel free to click the image to visit the above YQL Statement.
To be sure, the above example in itself shows that the link is not the issue, it's the content that is really the subject, as that's the item locked for which a Facebook Token key is required.

Related

How to comment on embedded facebook post on a website without leaving it

I recently made a fanpage and i have used embedded code from one of the post of my fanpage to my website.
So now It shows the post on my website and number of likes but i would like to show current existing comments which that particular post had got. Right now it is just displays the comment button and if i will click that then it will take me to the fanpage just for the sake of comment.
So heres what i need
1 - Comment on the embedded post without leaving the website to facebook.
2 - Displaying all the current existed comments ..
the image right now look like this
Thats very simple. First, you need to login user and ask for publish_stream permission. After the user is logged in, you just to display a button that triggers the function named comment, passing the ID (corresponding to the object user is going to comment to) .
You will also need an input field for inserting the comment (of course), and using jquery .value we will get the value of the input field .
PS: Specify NAME and ID on the message input field. I dont remember wich one is, put both of them .
After getting the variables, we will call FB.api, specifing the variables id and comentario than get the response for handling the result (if you want), you can try to reload the comment plugin, or refreshing the page .
function comment(id) {
var id = id;
var comentario = document.getElementById("message").value;
FB.api("/"+id+"/comments","POST",
{
"message": comentario
},
function (response) {
if (response && !response.error) {
alert('Comentado !');
} else {
alert('Erro !');
}
});
$("#atividade").html('COMENTADO');
}
That is very simple and fun, but you will need to get authorization from facebook platform to ask users for publish_stream permissions before production .
I think David's answer will just post a new comment, not show all post's comments.
Unfortunately there is not a option to show the comments on embed posts.
You need to get the post id, call a api to load all comments and so embed each one of them. Yeah, that's terrible...
Open the graph api explorer:
https://developers.facebook.com/tools/explorer/
Type {post-id}/comments on GET input and send it to see a response example.
And that's how you embed comments:
https://developers.facebook.com/docs/plugins/embedded-comments
I don't think loading all comments from all posts will have a good performance. I suggest you to create a button "see comments" which call the api. After that you can create the input text for new comments, like David said.

How to post a story to user's timeline

I am creating FB App that upload and post images, but I ran into a problem. I succeeded to take user's image and to upload it, and to create story about this, but story only appears in news feed, and not on user's timeline. Also, user's friends can see that story on their news feed on main page. I am using Open Graph, and custom object and action (create and photo). This is code from app:
FB.api('/me/appname:create?access_token='+access_token, 'post', {photo: object_id}, function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
console.log('Error: ' + response.error.message);
} else {
console.log(
'<a href=\"https://www.facebook.com/me/activity/' + response.id + '\">' +
'Story created. ID is ' + response.id + '</a>');
}
});
How can I make a story to show up on user's timeline? I read a lot of documentation, but couldn't find a solution to this.
Thanks,
Nikola
When you add action types on your Open Graph configuration's section you will find a list of capabilities you must check the last item on the list: Explicitly Share - This action can specify the user explictly... then you need to check your story with the API Graphic Explorer only for test purposes. Make a POST in there and the story will be publish in your timeline. Of course you need to have a correct meta tags in your page. Copy and paste your link with the meta tags here to be sure everything is doing correctly

Get user profile picture by Id

I'm now working on a web application which is mostly based of facebook graph api.
I hold some data about users - actually , the possible public data available - such as name and id.
I also know that a profile picture is a part of the public data, and I wondered how I'll be able to get a direct link to a profile picture of a user only by using their id?
http://graph.facebook.com/" + facebookId + "/picture?type=square
For instance:
http://graph.facebook.com/67563683055/picture?type=square
There are also more sizes besides "square". See the docs.
Update September 2020
As Facebook have updated their docs this method is not working anymore without a token. You need to append some kind of access_token. You can find further information and how to do it correctly in the fb docs to the graph api of user picture
Requirements Change
This endpoint supports App-Scoped User IDs (ASID), User IDs (UID), and Page-Scoped User IDs (PSID). Currently you can query ASIDs and UIDs with no requirements. However, beginning October 24, 2020, an access token will be required for all UID-based queries. If you query a UID and thus must include a token:
use a User access token for Facebook Login authenticated requests
use a Page access token for page-scoped requests
use an App access token for server-side requests
use a Client access token for mobile or web client-side requests
Quote of fb docs
You can use following urls to obtain different sizes of profile images.
Please make sure to add Facebook id to url.
Large size photo
https://graph.facebook.com/{facebookId}/picture?type=large
Medium size photo
https://graph.facebook.com/{facebookId}/picture?type=normal
Small size photo
https://graph.facebook.com/{facebookId}/picture?type=small
Square photo
https://graph.facebook.com/{facebookId}/picture?type=square
To get largest size of the image
https://graph.facebook.com/{userID}?fields=picture.width(720).height(720)
or anything else you need as size. Based on experience, type=large is not the largest result you can obtain.
From the Graph API documentation.
/OBJECT_ID/picture returns a redirect to the object's picture (in this case the users)
/OBJECT_ID/?fields=picture returns the picture's URL
Examples:
<img src="https://graph.facebook.com/4/picture"/> uses a HTTP 301 redirect to Zuck's profile picture
https://graph.facebook.com/4?fields=picture returns the URL itself
This will be helpful link:
http://graph.facebook.com/893914824028397/picture?type=large&redirect=true&width=500&height=500
You can set height and width as you needed
893914824028397 is facebookid
UPDATE September 2020
Facebook has new requirements change: an access token will be required for all UID-based queries
So you have to add your app access token to the url:
https://graph.facebook.com/{profile_id}/picture?type=large&access_token={app_access_token}
To get your app_access_token use the following url:
https://graph.facebook.com/oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=client_credentials
You find your-app-id and your-app-secret in the Basic Settings of your Facebook app in Facebook developers
https://www.avatars.io/
It's an API that returns the profile image when given a username for a variety of social networks including Twitter, Facebook, Instagram, and gravatar. It has libraries for iOS, Android, Ruby, Node, PHP, Python, and JavaScript.
you can get it with using this url : you will get the picture HD (max size)
https://graph.facebook.com/{userID}?fields=picture.width(720).height(720)&redirect=false
don't forget redirect=false or it will return an error
Use url as:https://graph.facebook.com/user_id/picture?type=square in src of img tag.
type may be small,large.
You can use AngularJs for this, Its two -way data binding feature will get solution with minimum effort and less code.
<div>
<input type="text" name="" ng-model="fbid"><br/>
<img src="https://graph.facebook.com/{{fbid}}/picture?type=normal">
</div>
I hope this answers your query.Note: You can use other library as well.
Through the Javascript SDK (v2.12 - April, 2017) you can get the details of the picture request this way:
FB.api("/" + uid + "/picture?redirect=0", function (response) {
console.log(response);
// prints the following:
//data: {
// height: 50
// is_silhouette: false
// url: "https://lookaside.facebook.com/platform/profilepic/?asid=…&height=50&width=50&ext=…&hash…"
// width: 50
//}
if (response && !response.error) {
// change the src attribute of img elements
[...document.getElementsByClassName('fb-user-img')].forEach(
i => i.src = response.data.url
);
// OR redirect to the URL above
location.assign(response.data.url);
}
});
For getting the JSON response the parameter redirect with 0 (zero) as value is important since the request redirects to the image by default. You may still add other parameters in the same URL. Examples:
"/" + uid + "/picture?redirect=0&width=100&height=100": a 100x100 image will be returned;
"/" + uid + "/picture?redirect=0&type=large": a 200x200 image is returned. Other possible type values include: small, normal, album, and square.
As per the current latest Facebook API version 3.2, For users you can use this generic method for getting profile picture is https://graph.facebook.com/v3.2/{user-id}/picture?type=square you can visit documentation for user picture here.
The possible values for type parameter in URL can be small, normal, album, large, square
For Groups and Pages, the profile picture is not available directly. You have to get them using access token. For Groups you have to use User Access Token and for Pages you can use both User Access Token and Page Access Token.
You can get Group's or Page's Profile Picture using the generic URL: https://graph.facebook.com/v3.2/{user-id}/picture?access_token={access-token}&type=square
I hope this is helpful for people who are looking for Page or Group Profile picture.
Simply Follow as below URL
https://graph.facebook.com/facebook_user_id/picture?type=square
type may be normal,small,medium,large. Or square (f you want to get square picture, the square size is limited to 50x50).
today I found a problem, the profile images was returning the default profile picture because a new requirement from Facebook to all the UID based queries, so just add &access_token=[apptoken] to the url, you can obtain your app token from here
You can use the following endpoint to get the image.jfif instead of jpg:
https://graph.facebook.com/v3.2/{user-id}/picture
Note that you won't be able to see the image, only download it.
Update July 2021
On top of answer by #EddyG, turned out that if you still not able to fetch the profile picture with app access token, the FB account must "allow" the FB app first then you should be able to fetch the profile picture with FB app access token.

Adding a Facebook comment on a URL and have it displayed on user profile

I am creating a web application that displays a list of images taken from Flickr and I would like a user to login through Facebook and allow them to comment on those images. I was able to get the login/authentication working but I am now having trouble to enable a user to add a comment (as oppose to a Facebook 'post') on a Flickr image and have this activity show up on the user's Facebook profile/feed (i.e "John Smith commented on a link").
Here is what I have so far:
var fbCommentApi = '/me/myappname_ns:comment?access_token=' + fbUserToken + '&method=post' + '&picture=[WEBSITE_URL]' + selectedItemId;
FB.api(
fbCommentApi,
'post',
{ message: txtObj.value },
function (response) {
if (!response || response.error) {
alert("Sorry, there was a problem. Please try again later. [API]");
}
else {
alert("Thank you. Your comment will appear shortly");
hideCommentBox(txtObj);
}
}
);
The above code doesn't create a comment but instead it creates a post on the user's timeline with the URL attached. So when I try to retrieve comments for the WEBSITE_URL item through Facebook Graph...
'https://graph.facebook.com/comments/?id=[WEBSITE_URL]' + itemID
...I end up with empty data being returned.
I have an Action Type called 'Comment' in my Facebook app and that's the action I am using when trying to add the comment.
Thanks in advance and I look forward to your answers.
UPDATE 1: It seems now that if I use Facebook Graph this way.. graph.facebook.com/me/appname_ns:discuss?access_token=[TOKEN]&website=[URL]&met‌​hod=post
..it would just add an entry to the user's Activity box in their timeline, I didn't even pass a comment or message parameter to the URL as a query string parameter. That could be part of the problem.
UPDATE 2: According to another StackOverflow question, there seems to be no way to get a view of all actions done by all users, it has to be done per user (an API call per user). Therefore another way of handling this particular issue is to save the comments (or whatever action performed) to our own database.
Well, an Open Graph action is not a comment, even if you name it comment …
If you want a real Facebook comment, then either get a reference to an object that actually can be commented upon; or substitute comment with post/link post.

Facebook tagging user on a photo in a Page Gallery via SDK and Graph is possible?

I'm trying to tag a user (having its userid), with a Graph request made to a picture just uploaded to a Page Gallery.
Permissions I use in the app are:
#"read_stream", #"offline_access", #"publish_stream", #"manage_pages",#"photo_upload",#"user_photos" and with a access_token to the session got from page_it?fields=access_token item (that works for picture upload in gallery).
And I use them to upload the photo to a Gallery on a Fan Page successfully.
When I try to tag the user with a graph request in the form:
POST to picture_id/tags with param: "to"->userid
I get only facebookErrDomain error 10000 as if permissions are not right.
From API Documentation seems that only user_photos and publish_stream are required and no mention to page-galleries photo is made.
I'm quite clueless about this issue.
It's possible. You need to collect the page's specific token by placing a call to /me/accounts. And then tag the photo using page's access token. Once you get that, you can tag the photo using it's Graph Object Id and user id whom you are tagging.
if (accessToken) {
var data = {
"access_token": accessToken,
to:userId,
x:x,
y:y
}
FB.api("/" + photoId+"/tags/"+userId , 'post', data, function(response) {
//here is the response
});
}
Hope it helps. The key is the access token that is specific to that page :)