Perl Facebook::Graph Post to Facebook Page as Page, not as Admin - facebook

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.

Related

Why Facebook Graph Api returns "Field is empty or disallowed by the access token"?

I want to list Facebook Page Post in a application. Therefor I use the Facebook Graph API.
I use the following URL:
https://graph.facebook.com/v2.9/674600022698736/feed?limit=100&fields=name,comments.limit(0).summary(true),permalink_url,shares.limit(0).summary(true)&access_token=XXX
I get the response, except for the fields': icon and shares. In the feature I need more, so maybe the problem is with more fields.
De Graph Explorer gives the following response for the fields icon and shared: "Field is empty or disallowed by the access token".
The shares are certainly filled!
See:
I've made the call with both the user and the page tokens, same result.
How can I solve this problem?
Although this post is old but has no answer, my answer might help someone:
If those edges are greyed out, it means you did not give or add those attributes in the access token your calling with. You need to give those permissions.
After adding such permissions for example for your case: like, comments you need to regenerate the token by clicking on the Get Access Token button and you should see it not grey anymore. Finally, you can Submit and get your desired response.
Classic Graph Explorer
1.
2
3.
Better yet, try the new beta Graph Explorer. Has a better GUI for the permissions option.
Beta Graph Explorer

Facebook (#100) App is not installed, when trying to remove a Page Tab Application

I get a "message: "(#100) App is not installed:" when i try to delete a pagetab application from a specific page using graph api.
Here are the steps to reporduce the problem.
Visit graph api explorer at https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.0
Get an access token with manage pages permission and request me/accounts using GET method.
You will see list of pages you are admin / owner of. Copy an access token from the page you wish to delete a tab. And paste that access token at the top under the access token field.
Now click the id of the the page (from where u have copied the access token) and you will see page data as a result of api/2.0/pageId GET method. This data contains all the infomration of page tabs. If it works till this part. You can just add /tabs a the end of the above command to see the information of tabs. i.e. API/2.0/{PAGE_ID}/tabs
Now you will see a list of page tabs, click on the id of one of tabs that is added by you(Not the fixed ones like photos and like tab). The id should be in the form of API/2.0/{PAGE_ID}/tabs/app_{APP_ID}. And choose the DELETE method from the dropdown.
Now click the submit button and you will get Error 100.
I have spent quite much of the time in resolving this but its not working at all for me. Please try the above procedure and help me knowing if I am doing something wrong or is it a facebook bug. I did all the above steps according to the inromation provided under facebook documentation.
https://developers.facebook.com/docs/graph-api/reference/v2.0/page/tabs

How can I post a link to a Page Wall as the Page?

I understand the procedure (i think), you grab the page access token, then post to the /page/feed edge with 'link' and 'access_token' parameters. However, when I do this, it posts to the page as myself rather than my page and shows up under 'Posts by others'.
If I try to post a message (instead of a link) it posts fine to my Page Wall as the Page (not myself).
Just curious if anyone can confirm this to be the case? Is this how its always worked and its just not documented?
Yes, you need the page access token. If it posts as yourself instead, you did something wrong.
To get page access tokens, get it from:
me/accounts
Then, use it to post the message.
If you are using the Graph API Explorer, make sure you replaced the access token in this form:
and don't add access_token= to your query.

Get all photos of a page using Facebook API

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

Facebook Apps: Additional permissions

I have a working Facebook app that most users will use just once. Leading into the Facebook workflow, users indicate if they want their wall to be written to or not. Based on that, I either ask for the publish_stream permission or not.
Later, a small percentage of users will come back and use the app again. Some of the people who previously did not want to write to the wall (and thusly I didn't ask for publish_stream) now want to write to their wall.
How do I request an additional permission after the user has already authorized the app?
Similarly, how can I query a user to list which permissions they have already granted?
It's as simple as adding the new permission to a new fb:login-button:
<fb:login-button scope="publish_stream">
Let me write on your wall!
</fb:login-button>
So for example you have the above hidden in a DIV and if the user tick a checkbox you show the DIV and prompt the new permission!
A good live example of this is on the Facebook Test Console:
Click login to "add" the application
Then click on examples
Under fb.api choose does-like
Now you can see that even after being *connected to the application (test console app), you can actually have another login button to prompt the user!
EDIT:
To check if the user has granted your application a permission, just use this FQL:
SELECT read_stream,offline_access FROM permissions WHERE uid=me()
This would return something like:
[
{
"read_stream": 1,
"offline_access": 0
}
]
To test it, just use the test console posted early.
EDIT 2:
To construct the link yourself without XFBML or Javascript, you just need to add the scope parameter with the additional perms (reference):
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=publish_stream
Or if your are using the PHP-SDK:
$loginUrl = $facebook->getLoginUrl(array(
"scope" => "publish_stream"
));
I was looking at this the other day! If you read through http://developers.facebook.com/docs/authentication, there are several different ways of displaying a little popup box to request extra permissions.
I'm not sure how this works with a Facebook App, but I know on a website using Facebook Connect, if you try to request permissions that the user already has accepted, then the page automatically redirects back to the redirect_url that you set.