I have a facebook page, a facebook app and an administrator facebook account of that page.
Now i want to publish a link on that page (i don't care how).
Since now i did that by getting a user access token of the admin for my app, then get the page, get a access token for that and then post with the admin on the page via my app.
Now the token expired and i read in the documentation that i can:
For example, if a user granted your app publish_stream permissions, your app can use an app access token to publish a status update on their behalf.
So i got the application access token.
But now i don't know how to go on, how can i publish on the page's wall with that token ?
I believe the application access token is for publishing on behalf of users. For pages, you should be using the page access token.
https://developers.facebook.com/docs/reference/api/page/
As described in the link above
To perform the following operations as a Page, and not the current user, you must use the Page's access token, not the user access token commonly used for reading Graph API objects. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including application profile Pages) to which the user has administrative access, along with access_tokens for those Pages. Alternatively, you can get a page access token for a single, specific, page by issuing an HTTP GET to /PAGE_ID?fields=access_token with the manage_pages permission, as described above. Publishing to a Page also requires the publish_stream permission, unless otherwise noted.
After more research i think there is no way to publish on pages with only a app token.
It is still possible to post on the wall of the users that authorized the app, but not on their pages ...
Related
I have a problem with Google Drive sync. I can insert, update, delete, get from a specific Drive account as long as I get the access token from the authorization page.
Does someone has a solution for that?
Read about "offline access" and "Refresh Tokens". By requesting offline access when the user authorizes your app, you'll receive a refresh token which you can use to obtain an access token at any time.
I have been trying to work through the instagram API but I am caught up on getting the access token. In the instagram API, it states:
At this point, we present the user with a login screen and then a
confirmation screen where they approve your app’s access to his/her
Instagram data.
Now I was wondering what if you don't want the user to have to login? For instance, say I have a site and I only want to display my latest images. The user should not have to login to be able see these. However, all the endpoints(http://instagram.com/developer/endpoints/) to get a users media require the access_token provided by the user login. How can I just get my latest images without a user login?
Which endpoint are you using?
The GET/users/{user-id}/media/recent endpoint requires authentication. So there is no way to get a specific users' media without an access token.
At the time of writing, this seems to work without needing authentication:
https://api.instagram.com/v1/users/USER_ID/media/recent/?client_id=CLIENT_ID
You could generate an access token with your instagram account here: http://instagram.pixelunion.net/,
then use this url: https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN to retrieve all the info about your latest 20 posts including images urls.
I am just getting started on automation of posting messages on FB fan page on behalf of Admin(For e.g. I run a code in eclipse and It should post message on page). I read couple of similar questions on stack overflow, went through docs on FB API's but seems I am lost in this vast sea. I have few doubts.
Do I need to create an APP on Facebook that would interact with it's APIs. Can I not directly interact with them in my code(Java)?
What's flow of request to post status? My code -> My FB App -> My page or My Code -> My FB page
I see two different types of authentication, Server side and Client side. Are they both required or I can choose one of them.
Any link to some sample code for this would be extremely helpful.
I need to present this in a competition and have got only 1-2 days and figuring out stuff is taking too much time.
Any help would be appreciated.
Thanks
1 You need a Facebook application through which you're communicating with Facebook. An app can request various permissions and when granted by the user, you can access the user's data or pages. Of particular interest will be the manage_pages permission (see an overview of permissions).
2 The basic steps are: The app requests permissions to do something, the user grants them and after that you obtain an access token which you can use to interact with the API. So initially, the flow is: your code > the app (and the user) > Facebook API. After that, it's your code > Facebook API (with the access token passed as GET parameter in the URL).
The above is if you're doing user related things. For pages, it works somewhat the same but you still need a user access token. If you have manage_pages permission, you can visit /me/accounts (with the user access token) and you'll get a response that contains a page access token. That token can then be used to perform actions on the page on behalf of that user. This only works if the user is an admin of the page.
3 I have only used client side authentication so far but it's also possible to do server side only. Some access tokens live longer than others. For example, a user access token is valid as long as the user is signed into Facebook. But other access token (such as for pages) live longer. You can then store the access token and use it repeatedly.
4 At the time of writing, I'm not familiar with Java libraries for the Facebook API so I can't help you here.
I'm trying to write a facebook application using Java tomcat with RestFB.
the restfb documentation shows the following:
Create a Facebook Application
Request https://graph.facebook.com/oauth/authorize?client_id=MY_API_KEY& redirect_uri=http://www.facebook.com/connect/login_success.html& scope=publish_stream,offline_access,create_event
Facebook will redirect you to http://www.facebook.com/connect/login_success.html? code=MY_VERIFICATION_CODE
Request https://graph.facebook.com/oauth/access_token?client_id=MY_API_KEY& redirect_uri=http://www.facebook.com/connect/login_success.html& client_secret=MY_APP_SECRET&code=MY_VERIFICATION_CODE
Facebook will respond with access_token=MY_ACCESS_TOKEN
I think that i may be looking at the wrong instructions and this is for a facebook connect or anything else besides an actual facebook application inside apps.facebook.com/app_name.
I would really appreciate any relevant information regarding the issue. I'm simply trying to create a simple facebook application that prints the name of the user.
In general after I fetch the acces token of the user i can do the following:
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
User user = facebookClient.fetchObject("me", User.class);
out.println("User name: " + user.getName());
My problem is how do i properly fetch the access token of the user? in the information i showed at the top of the post, it shows that i need to make 2 requests. the first for the code and the other for the acess token. and the request for the access token actually reveals my app secret key to the user because each time i forward him to a different page the user can easily view the get and set parameters.
so i guess i'm pretty lost here.
please help! :)
thanks
update after comments
with these instructions i need two times to redirect the user's page. first to get the code and then to get the access token. the user can see these two redirections and because of that he can easily see the facebook application key and secret key from the get parameters. how do i make sure that these steps are hidden from the user?
As stated in the comments, these are the steps you need to take to access Facebook's graph API. However, to answer your second question:
"How do I make sure that these steps
are hidden from the user?"
Only the first request should be performed by the user's browser. The purpose being that Facebook wants to make sure it is the sole authorization provide for the user's Facebook identity. Depending on the application you are writing, you would either use the redirect URL to point to the default redirect URL that you specified, or specify a custom url on your website that you will use to retrieve the token. The first approach is typically used by stand-alone applications such as mobile devices that can control how the browser handles redirects. The second approach would be used for a custom web-based application. Once you receive the access token, then you would perform the second operation within your code (using your favorite http apis) and not through the browser. The redirect on the access_token url is compared against the redirect url specified on the authentication-url. Facebook uses it for validation only and does not perform an actual redirect on the successful completion of the request.
Here are the high-level steps:
Redirect user's browser to the authentication-url specifying the appropriate redirect_uri
Retrieve verification token from redirected browser request
Perform access_token retrieval using your preferred HTTP framework (no user input required)
Parse results and retrieve access token
Initial restfb with token and use as needed
The REST API has been deprecated. You should look in to the JavaScript and Graph APIs instead - there is a good article on this here: http://ocpsoft.org/opensource/creating-a-facebook-app-setup-and-tool-installation/ (Three part series, very detailed :)
I've developed a Chrome Web Store app using Google App Engine. I'd like to follow these instructions: http://code.google.com/chrome/webstore/docs/identify_user.html#realm
But I need to call User::getFederatedIdentity() so that I can call the Chrome Web Store licensing server and find out if the user has purchased my app.
The trouble with that is, in order for UserService::getCurrentUser() to work, the user needs to be logged in.
The trouble with that is, when I call UserService::createLoginURL() to generate a redirect URL, the redirect URL takes the user to... the OpenID approval screen. This happens even though I've set the App's OpenID realm, as per the instructions in the page linked above.
Is there a way for me to do what I want but still use the User and UserService classes?
(Possibly a legit alternate phrasing for this entire question: using Google App Engine's UserService class, is there a way to request permission from the user to access their federated identiy, without also requesting permission to access their email address?)
Thanks in advance!
Please reread how to skip the OpenID approval screen. Have you set the realm? And are you asking for any information other than the URL? If you request the user's email address (or other information), then it is necessary to inform the user and obtain their permission to grant access to that information.