I am new to Facebook API but I have to get all photos from a Facebook page. I managed to get a graph api query that returns all pictures of only the first ever created album on the page which is the profile picture album. For example:
https://graph.facebook.com/227843870675663/photos
But I need to do the same for all other existing albums in the page. Any pointers are really appreciated.
Try this and let me know how it goes for you. I've successfully pulled all photos from a Facebook page.
Ensure that you are an Admin of the Facebook Page.
Go to:
http://developers.facebook.com/tools/explorer
In the API Navigator, you can access /me to bring up the basic information of yourself.
Try typing in /me/accounts to see if you can see anything. It should give you an error.
You need to enable certain permissions to make this Graph query. Choose the relevant permissions in the right sidebar. According to this doc you need the pages_show_list and pages_read_engagement permissions for this query.
Click on "Get Access Token" which will give you a new token with the updated permissions. You may get a popup window where you have to confirm which page(s) you would like this access token to be able to see.
Now try /me/accounts again. You should see a list of pages that you enabled access for, inside the viewing window.
Find the Facebook Page you want to query, and click on the "id" field. This ID is needed for making any queries related to this page.
Next, on the left window, you can see "Node: " and a + sign. Click on the + sign to see what options you have.
Click on the + sign and scroll down to "connections" and select "Albums"
The child-level, select "Photos"
The "Photos" child-level, select "source"
Now click "Submit" on the right hand side.
If the above doesn't work, you can try copying the following URL into the API explorer:
YOUR_PAGE_ID/?fields=albums.fields(photos.fields(source))
You will see a JSON returned with the URL of some/all of the photos in your selected Facebook Page.
Click "Get Code" and it will show you the Javascript or raw URL used to access this information.
The "cURL" tab will show the URL which will look something like this:
https://graph.facebook.com/v15.0/YOUR_PAGE_ID?fields=albums.fields(photos.fields(source))&access_token=YOUR_ACCESS_TOKEN_HERE
You can copy that URL and plug it into your browser. You should see a JSON of all your photos, and each photo's corresponding URL on Facebook's CDN.
Getting photos posted to the feed, not just photo albums
To do that, you need to run a slightly different query:
https://graph.facebook.com/v15.0/YOUR_PAGE_ID/feed?fields=attachments
Getting high resolution imagery
Many of the image URLs provided by the queries above will only provide resolutions up to 720px. If you want higher resolution images, then you need to find the target.id for each subattachment, and perform a separate graph query for each image to obtain the other resolutions. It looks like this:
https://graph.facebook.com/v15.0/YOUR_IMAGE_ID?fields=images
Watch out for expiring tokens
The token generated above will only work for approximately 1-2 hours. If you want a longer lasting token, follow the steps in this post here.
When you get your Facebook user, you can:
get the list of all its
albums
get the user's profile
picture
get the
photos
the user (or friend) is tagged in
They respectively need those permissions:
user_photos or friends_photos
not needed
user_photos or friends_photos
UPDATE:
If you want to get those information from a Facebook page:
Photos - The Page's uploaded photos.
Albums -
The photo albums the Page has uploaded.
Permissions are: any valid access_token or user access_token
Related
To fetch a Facebook page videos I use the code below:
new GraphRequest(mAccessToken, "Page_ID/videos", params, HttpMethod.GET, new GraphRequest.Callback(){}
What I want is to fetch the 'Featured video' of a Facebook page, but according to Facebook documentation in the link below, 'featured_video' parameter is visible only to the page admin, What is the logic behind setting this parameter to be only read by the page admin?
https://developers.facebook.com/docs/graph-api/reference/page/
Where can I report / ask Facebook to get this parameter result allowed to be read by others than the page admin?
Graph API /{page-id}/featured_videos_collection gives Featured Videos Collection for a Facebook Page. You need to use page-access token with page-id.
See for more info. I have not tested that API. Check if it is working.
You need to use {page-id}/featured_videos_collection edge to get featured video with normal user with page-access-token. While authenticating user, you need to get user_pages permission. Admin can get featured_video in directly without giving user_pages permission in {page-d} edge only. May be because of that Facebook have kept different edge for getting featured video of a page and 'featured_video' parameter is visible only to the page admin
On my website there is possible post image from computer. But I would like also provide user to post image from facebook user album. I can imagine some dialog like "Facebook login" which will open faceook images and provide user to send image from facebook to my application. Does something like that possible? Many thanks
Yes, it is possible.
I assume you have a little experience with facebook api.
trigger login FB login window and request user_photos permission
make a query to facebook to get (all/random/a few) user albums like so me/albums?fields=id,count
If a key count is set, there are photos
(I would collect all IDs of albums containing photos and make a query to facebook with ech one ID)
Then again, query to facebook like so /%album-id%?fields=photos.fields(images)
Now you have an array of URLs of images which, for example you show to a user and after he selects, you download it and upload to your server
Since you did not request a solid code, I will provide you with at least with a little snippet, or show an illustration how to do that. http://paste2.org/hvGkngIL. (a metod index) (Might not work properly, since I cut it from a PHP framework I work with)
Using the Perl module, Facebook::Graph, I have created some basic perl code that can post to my own wall. I can share a photo on my own wall. I can also post a simple wall message to one of the pages for which I am an admin. However, when I try to post a photo to the page, it posts as me, not as the page.
Here is the sample code that posts as me, to the Facebook page. I need it to post as the Page, not as me.
# previously, I obtained my Page's accesstoken, and other credentials
# including the Facebook Page ID
my $fb = Facebook::Graph->new(
app_id => $facebook_application_id,
secret => $facebook_application_secret
);
$fb->access_token($facebook_accesstoken);
my $rstring = $fb
->add_photo
->to($facebookPageID)
->set_message('Look at this really cool photo!')
->set_source('./raw_image_example.jpg')
->publish
->as_string;
print "$rstring\n\n";
I am trying to figure out how to create a post to the wall of a Facebook page, as if it is being posted BY the page, not by me.
I am trying to do that with the CPAN module, Facebook::Graph, located here: http://metacpan.org/pod/Facebook::Graph
I cannot, for the life of me, figure this out. Any help would be most welcomed!
I went through the same trouble, so let me share what I did step by step so it might benefit other people:
After going to developers.facebook.com to create an app, you
go to https://developers.facebook.com/tools/explorer/
There, on the top menu named "Graph API Explorer" you select the app
you just created
Then, on the righthand side, there is another menu named "Get
Token", in which you select "Get Access Token", then a pop-up window
will appear, you to the extended
permissions tab, and check "publish_pages" and "manage_pages"
options and click on "Get Access Token". It will pop-up a window
asking you to confirm you want to grant access to this app. It will
produce a long token.
Then, you select the menu Get Token again, and you will find in this
menu the list of the pages you manage, select the one you want and
it will show its related access token.
Now the token received is only temporary like 2 hours or something.
You want something that last 60 days and renewable, so from your
server you do a curl request:
https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=$facebook_application_id&client_secret=$facebook_application_secret&fb_exchange_token=$facebook_accesstoken
Facebook will output something like this:
access_token=ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ&expires=5184971
Then, you can post as your page using your fine code.
I hope this helps.
Enable manage_pages permission to get a code.
Submit code to get user access token for your account (you are manager or content_creactor) for query everythings.
Queried your account by calling /me/accounts, you will get page access token. one account can manage many pages. So use JSON to choose which one do you want.
Use those page access token to post msg or photo as normal. https://graph.facebook.com/me/feed
(note that it is not /feed) since page access token contain the ID already.
I've created a timeline app that adds events to user's timelines in the past. I've noticed its simple to add tags, places, and external images to OG objects and actions.
However, I can't seem to find a good way to connect to a facebook photo (i.e. a photo from the user's albums). Adding a link to the photo's picture in the images field doesn't work the expected way without an access token (which will presumably expire)
For example: /namespace:action?image=http://graph.facebook.com/10100111692798728/picture will show a '?' photo (in aggregations and elsewhere) unless you pass a valid access token in too (that can't work permanently). This is presumably because whatever identity is going out to request the photo is not allowed to access it this way.
It doesn't seem like you can connect your own actions to photo objects either. Is there a solution to this that I've missed. I'd really like user's to be able to add a photo from their facebook albums to an action from my app (i.e. them doing the 'action'). It would be nice if you didn't have to point directly at an image on FB's CDN somewhere, it would be even nicer if there was a way to point directly at the FB open graph object.
Thanks,
Grant
It is possible to connect the action with Facebook photo like this:
POST /me/do:action?object=[objectId]&access_token=[valid access token]
If the [objectId] is an object id of existing photo - it will show the picture and correct link to the full size facebook photo on timeline.
I have a photo id "2296309061879" and it work perfectly in
http://www.facebook.com/photo.php?fbid=2296309061879
I use the Graph API link:
https://graph.facebook.com/2296309061879
get false as ALWAYS......
How about it work with my Access Token generated in my application that create by myself immediately?
https://graph.facebook.com/2296309061879?access_token=AAABnQBRA8V0BAF6Idy3ZBXD0As7kEt3ogZCp5yZB435MaZBVZCUV8xZCawgoHewciScXWDdMuiBk5sIWZCI1uJM64H3oWAl6eenZBlSutDwB9D5sT3kahRcK
still get false as ALWAYS......
So, how to get the photo from facebook with the photo id?
Another serious problem is, I use facebook's api to upload a photo to my account, and it return me the photo id. then I goto my facebook to check the photo: it does not exist in any album!!
What's wrong with facebook?
Because your app doesn't have rights to access it.
This is a public photo from my facebook:
https://www.facebook.com/photo.php?fbid=2651141672758
It also returns false if I try to use https://graph.facebook.com/2651141672758
If I try it in the explorer I also get false:
https://developers.facebook.com/tools/explorer/?method=GET&path=2651141672758
If I click on the "get access token" button, and select the user_photos permission ... it then works.
Edit: Note the first set of bullet points in the Graph API docs for photos: https://developers.facebook.com/docs/reference/api/photo/ - It would appear they're wrong, or there's a bug currently as it states any valid access token should be able to see public images and that's demonstrably not working. In order for the explorer app to list my albums and/or photos I have to explicitly grant it the user_photos permission