Use Facebook Graph Api to get info about comment? - facebook

I want to get info (text and uid) from comments in my application.
https://graph.facebook.com/commentID
I think I need my apps access token to get the comment info. How do I get it and echo/alert with comment's info?

you need to request the user to allow your application and then use the access token you get in the request to the Graph API...
the allow of the application can be done in both server side or Javascript (I prefer JS)
an example for how to allow an application and invoke a graph api call can be found in the facebook developers js sdk documentation below:
http://developers.facebook.com/docs/reference/javascript/FB.login/
function loginAndGetData(){
FB.getLoginStatus(function(response){
if(response.status=="connected"){
FB.Api("commentID",onGotData);
} else {
FB.Login(function(response){
if(response.status=="connected"){
FB.Api("commentID",onGotData);
}
});
}
});
}
function onGotData(data){
console.log(data)
}

Related

how to integrate facebook js login and laravel socialite?

i'm facebook js sdk for users login,
at the server side i want to get the user data
i'm trying to use
Socialite::with('facebook')->user()
to make it work it need 2 query string code and status
in my JavaScript i'm using the following
var auth_status_change = function(response) {
console.log(response);
if(response.status == "connected")
{
window.location = "{{URL::to(App::getLocale()."/fb_login")}}?code="+??+"&state="+???;
}
}
FB.Event.subscribe('auth.statusChange', auth_status_change);
how to get the state and code values to create a valid callback URL for socialite
You're trying to combine 2 things that do the same thing, but one on the server side and one on the client side, that won't work.
Laravel Socialite uses your app token to redirect your user to Facebook, authorize your app to use Facebook on their behalf (token) and provides you with user data. With the token you can do API calls from Laravel.
The Facebook JS SDK does the same thing, but in the browser. It fetches a token which it uses to do API calls.
Check out https://laracasts.com/series/whats-new-in-laravel-5/episodes/9 on how Socialite works.
Unless you are using the JS SDK functionality, you can leave it out and just add a link to a socialite route which redirects it to Facebook. That call will provide you with the code and state required to fetch the user.

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.

Facebook Javascript SDK feed doesnt contain status updates

Here is the code for fetching the activity feed from Facebook Javascript SDK
function fetchFeed(){
FB.api("/" + {My-User-ID} + "/feed?limit=5", function (response) {
if (response.error) {
console.log("Error fetching feed");
} else {
console.log(response);
}
});
}
But the feed obtained doesn't fetch me the status updates from my account , it fetches my other activities like page likes but not the status update .
I think that's because your Access Token is missing some of the permissions required to obtain the user statuses. These permissions are user_status and read_stream. If you are using Javascript SDK for authentication, you can ask for extra permission in the code using:
FB.login(function(response) {
// handle the response
}, {scope: 'user_status,read_stream'});
You can always test your code using the Graph API Explorer. It gives you flexibility to manually choose the permissions and test you queries.
PS: If you are only concerned about the statuses, you can use API endpoint like /{user-id}/status and /{user-id}/posts to narrow down your results. Take a look at the documentation on /{user_id} edges to find out the difference among these edges.
Thank you Rahil for the suggestion , The Graph API Explorer Page helped me to find out the solution, my app (PI CONTROL) didn't have the right permissions in its access token to fetch status updates . LAter Obtained a new access token with right permissions for my application. The steps are depicted in the screenshots below
1.Go to the Graph Explorer Page Graph Explorer
2.Select the app for which you want to give the permissions for
2.Click on Get Access Token
3.Select the right permissions for your app

Facebook app - permissions varying from tester to tester

Bit of an odd one: I've created an app that uses a jQuery AJAX request to query the Graph API and access a list of a given user's Likes (someone on my Friends list). I can use this within my app, and I get the same result as if I'd run the query through the Developer tools Graph API Explorer site (https://developers.facebook.com/tools/explorer).
The fun begins when people on the Testers list for the app (which is sandboxed) perform exactly the same actions, with the same friend (who isn't on the testers list); they don't receive any data back from the Graph API at all.
The testers have granted my app all the same permissions as I have, so why would we be getting different results?
Finally - I think I've found the solution.
By switching the Facebook JavaScript SDK file to a direct link rather than an asynchronous download, and calling the FB.login function with extra permissions defined in the scope later down the page:
FB.login(function (response) {
if (response.authResponse) {
// init app here
} else {
// cancelled
}
}, { scope: 'user_likes,friends_likes' });
... the testers are able to access their friends' Likes. Phew!

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/