How to use Facebook API to get my OWN timeline/posts data - facebook

I am developing a site for a ONG that news section is a Facebook timeline post of your OWM profile.
The social_page plug-in is not good and not responsive, maximum width of 500px and does not have a adaptive design.
So I think I can use the Facebook's API to get information about fields ("message", "picture") from Facebook profile.
I do this in client with javascript, and I will read data and make simple HTML (photo and message) for the news.
the code for that is:
FB.api(
'/user_id/posts',
'GET',
{ "fields": "message,picture", "access_token": "access_token" },
function (response) {
console.log(response);
}
);
But how i can do a Facebook token that grant access for this information with no expiration data?
The problem here is: Facebook will expire the access token, and I don't find a way to grant permission only to read posts with no expiration in client code.
Someone has a solution or knowledge if its possible?
Thanks.

Related

Can I post reviews on Facebook through an API?

Is it possible to post user reviews to a FB page via an API?
I want to have an app on a phone that will let users review my business when they walk in to my store.
Edit:- This is what I've tried so far.
I used the passport module in Nodejs for authentication and was able to retrieve the access token from FB, including manage_pages, publish_pages and read_insights.
app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['email', 'manage_pages','publish_pages','read_insights' ]}));
My passport strategy has this
clientID : configAuth.facebookAuth.clientID, //my app's client id
clientSecret : configAuth.facebookAuth.clientSecret, //my app's client secret
callbackURL : configAuth.facebookAuth.callbackURL, //the callback URL after authentication
profileFields: ["emails", "displayName"]
I am able to post as the page using the NPM FBGraph module.
var graph = require('fbgraph');
graph.setAccessToken(req.user.facebook.token);
graph.post("{My page's ID}/feed", "Message test", function(err, res) {
console.log(res); // { id: xxxxx}
});
This lets me post the "Message test" to my page's feed.
I am not able to find a reference to post reviews for the page through the Graph API though and was wondering if that is possible.
https://developers.facebook.com/docs/graph-api/reference/page/ratings#Creating
You can't perform this operation on this endpoint.
Meaning, it´s not possible. Not sure what you would do with publish_pages though, because ratings/reviews are made by users, not by pages...If it would be possible, then only with publish_actions.

Problems with facebook api posting to company page using application id: (#200) The user hasn't authorized the application to perform this action

I am stuck with access rights in trying to post on facebook company page.
I have created an application and gotten appId and secret.
I have linked the application to the existing facebook page.
I have retrieved an accessToken for the appId.
But get the response: "(#200) The user hasn't authorized the application to perform this action."
Which user does the error statement refer to? the AppId user? The administrators of the page (me)? And where can I grant these missing rights?
I am trying to achieve that the post functionality is not facebook-user-dependent, but is company (or appID) dependent.
I am really confused about this...
Off course we could create a bogus user (kept in the company files) and post as this user - but that goes against the Facebook policy, and that is not the road we want to go down...
function FB_doPost(link, message, accessToken) {
console.info('doPost');
FB.api('/pageid/feed', 'post', {
access_token: accessToken,
message: message,
link: link
}, function (response) { if (!response || response.error) { console.info('error occured: ' + response.error.message) } else { console.info(' post id: ' + response.id) }; }
);}
In order to post to a Page "as Page", you need to do the following:
Authorize a Page Admin with publish_pages and manage_pages
Use the /me/accounts endpoint to get a Page Token for that Page
Use that Page Token with the /pageid/feed endpoint to post as Page
Make sure you know about the difference between Access Tokens, here are some links about that:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Facebook Graph API access token is different from what I am getting via Oauth

I made a facebook app.
The app is to get all the pictures my page is tagged in.
When I use the graph api explorer with graph api explorer as the application to get the access token, This access token returns me all the data required(In this case photos my page was tagged in using (me/accounts) then get the access token of my page and then me/photos/tagged)
But the same process when I repeat with selecting my application in the graph api explorer. It does not give all the data
Both have same permissions.
Am I doing something wrong ?
I think is a little bug fix of API graph:
FB.api(
'/id_cta',
'POST',
{**"access_token":access_token**,"web_url":url},
function(response) {
console.log(response);
}
);
Important: ask for scope manage_pages and pages_manage_cta.

Can't create facebook album via graph api

I can't create a Facebook album via graph api. Now, it always throws a error
(#10) Application does not have permission for this action
I don't know why. I'm sure I have the correct access token (it is a valid, it does not expire). I have the same error in php & javascript.
My example code in js:
FB.api('/me/albums', 'post', {
access_token: access_token, // it is a valid
name: 'test album 1',
message: 'test album 1'
}, function(res) {
console.log(res); // throw a error "(#10) Application does not have permission for this action"
});
Does Facebook have some bugs or I missed something?
Edit: I found the correct answer from https://developers.facebook.com/bugs/680991411993635/:
Even though you are using a Page Access Token, you need the
user_photos permission in order to create a Photo Album as the Page.
Facebook does have some bugs...don't we all?
You actually did miss something - you need the correct permissions.
In order to create an album, you'll need to request the publish_actions permission from your users. This permission allows your application to publish stories to the users feed including new albums.

How to get all facebook pages id associated with my account?

I want to get the statistics of all the pages associated with my account on facebook, i have the code to get the statistics of a page, i just want to get the page id of all the pages associated with my account, how can i do this?
Please help.
Thanks.
You'll need to request the manage_pages permission (more details here), once you have the aquired the permission, all you have to do is make a request to :
https://graph.facebook.com/YOUR_FACEBOOK_ID/accounts.
The return value will be a JSON with all the pages/applications that are associated with your account.
You can also use this great tool that facebook provides - The Graph API Explorer (/me/accounts) to explore what other information you can retrieve without having to write a single line of code :P very useful.
FB.api('/me/accounts', function(response) {
for (id in response.data)
{
page = data[id];
page.id;
page.name;
}
});
You can use Javascript API to do this, read more :http://developers.facebook.com/docs/reference/javascript/