Facebook return ID and me.name - perl

I am really lost with these two problems with Facebook API...
All has been working fine posting to user walls, but I have one client with a page. The page was created from scratch, not via themselves as a user - ie they did not login and create a page they just started from the Facebook welcome screen>create page.
There page works fine, however,
1) Our system is submitting a post via API and receiving an ID in return (eg {"id":"123456_123456"} back from Facebook - this tells me facebook has accepted it and has given me an ID for the post.
However, the post DOES NOT appear on the page it relates to (and I have checked where it is submitting it to and it is the correct User ID). This system has been working fine for all other users.
2) When the login occurs via Javascript for this user, we get an empty value for "me.name" (we get me.email etc, just no name)
Is all this normal, or do pages have a different technique to posting and retrieving data?

Email is a private data of facebook user , It is a permission issue what you are encountering
The only way to get the users e-mail address is to request extended permissions on the email field.
After logging in .
This is how facebook api works , w.r.t revealing private data of its users

Ok I solved this one, I don't doubt the ability of anyone here - perhaps my question is still being misunderstood...
Some Facebook pages (especially business pages) where the page hasn't been created by an existing user are different to Facebook groups and user pages. You cannot just submit using an short ot long term access token.
You have to call facebook as http://graph.facebook.com/ID_OF_PAGE/accounts with your token first.
Facebook returns a list of pages, each with their own unique ID and a token for each.
You then grab the token for the page you want then resubmit with the page ID and that pages OWN token - and voila it posts to it!
Their are still bugs with Facebook as I found. It says on one business page I created for a client "Use Facebook as ." - ie the name is missing before the "." - it should say "Use Facebook as MYNAME."
This introduced another problem with the JS FB.login because the name of the person returns undefined. I had to verify their Email instead - other wise it says "You are logged in as ."
I think its because FB lets you create a page from scratch, as a new user, and without logging in as yourself - then some values are not being set and it messes up.
Perhaps may help someone...

Related

How to get post ID of Facebook shared URL, or how to get all posts shared via Facebook app?

Goal
My goal is for a user to share something he created on my site to Facebook, and for me to display all comments on my own page using the Facebook comments plugin.
So my ideal flow would be:
User creates content with example id vjrjf834fdkfj, and shares using public URL http://example.com/vjrjf834fdkfj/.
User shares this URL on Facebook via my Facebook app ID. The post ID is 1234567.
I get this post ID. (This is what I need help with)
I store this in my database.
Whenever a visitor visit the page http://example.com/vjrjf834fdkfj/ I look up in the database what the post ID is (1234567 in this example), and call the Facebook comments plugin using this post ID.
What I tried
Attempt #1
First failed attempt: read the post_id field of the FB.ui callback but this response is typically empty because Facebook says that:
Only available if the user is logged into your app using Facebook and
has granted publish_actions. If present, this is the ID of the
published Open Graph story.
My user is not always logged into my app via Facebook, because he can also create a normal account.
Attempt #2
So my next attempt was to get a list of all posts of this app by calling the Graph API. I have a "basic" app with the "Website" platform set to my website URL (www.example.com). Given this list I might filter this on the relevant URL and voila, get the post ID for the right URL.
I can create an access token and call https://graph.facebook.com/v2.8/{app-id}/objects?access_token={token}, but this gives an error The parameter type is required. And when I try to get a list of object types by calling the /object_types endpoint, I get an empty list.
Attempt #3
I also played a bit with creating a Page Tab but the documentation makes no sense to me as to how that would apply to my case. I ended up with two extra pages, all empty, and not what I want. However, I could live with an extra page on my Facebook page showing a list of all posts that have been shared (so these posts would appear here and on my user's timeline).
Questions
So:
Why is this object_types list empty? I expect that something like "post" would show up here, allowing me to get a list of all posts associated with this app ID.
If this is not possible, how can I still achieve my end goal?
Thanks.

How can I detect if a certain post on a Facebook page has been deleted?

I am planning to build a small side project that stores posts from particular public pages. And detect if they delete the post later. Something similar has been done for Twitter. But I couldn't find similar projects for Facebook.
Like this: http://politwoops.sunlightfoundation.com/
But for Twitter. I will do it in Python or C#
How can I go about it?
Any particular code or projects I can learn from?
The only way to check if a post is not there anymore on Facebook is to search for it with a User Access Token of the User who posted it. Every Object on Facebook gets a specific ID, you only have to check if that ID still exists. If not, you get an Error from the API.
For example: https://developers.facebook.com/tools/explorer/?method=GET&path=10203433018378479&version=v2.0
The path parameter is the ID of the Post.
Keep in mind that you need the read_stream permission for that, and you need to let Facebook approve it for other users or it will only work for Admins/Devs of your App. It is not very likely that you will get the permission approved for this though. It usually only gets approved for Apps on "Platforms without a native Facebook experience".
Edit: My bad, i was thinking about User posts, but your question was about Pages. In that case, all you need is an App Access Token (App-ID|App-Secret). The API Call would be the same, you just need to know the Post ID.
About Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens/
http://www.devils-heaven.com/facebook-access-tokens/
For getting the feed of a Facebook Page, see the Facebook docs (including code samples): https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/
You can use graph api for this. If it's a public page, you can follow these steps:
Create your application in Facebook developers site
Setup the basic graph auth mechanism with your favorite language and get unexpired token.
Use your unexpired access token to do these tasks:
Enter the id of the pages you want to crawl http://graph.facebook.com/[insert page id or url here]/feed
Add post title, postID to your database.
Create a scheduled task on your server to do these tasks:
Select all / page based etc posts on your database and send a request to: http://graph.facebook.com/[insert post ID here]
if it returns it means it's still there. otherwise it will return an error.

Posting to a Facebook page on behalf of page using a Facebook application by anyone

I have a web page linked to a Facebook application where users can log in by their Facebook account.
I have also a Facebook page for my application where anybody can post.
What I'd like to achieve is the following:
- An ordinary user logs in to my web page using her Facebook account,
- She adds an information to my web page (for example a book name),
- That information is instantly posted to my application Facebook page under page's name (for example "this book is read by someone").
I don't want it to be posted by the user, I don't want it to be posted by myself (admin of the page).
I don't want to mention about the user, it will be anonymous information.
But I couldn't find a way to do it either as JS or PHP.
Any suggestion is welcome.
Many thanks.
You will need to get a page access token. https://developers.facebook.com/docs/facebook-login/access-tokens/
Get it, store it somewhere on your server – and then use it when making the API call to post what the user entered.

List Facebook Page events on website for a Venue using FQL or Graph API

I am helping out a friend with a site for a venue that lists all events on FB with a location, ticket URI, time, etc.
I have found lots of info on how to get the data, but what I am unclear on is how to get public events without being logged in to FB.
What type of tokens do I need to have a website simply pull events data and display it to visitors?
Basically, what I am attempting to do is show a set number of upcoming events and assume that the visitors to the site are not logged in to FB.
On this page, https://developers.facebook.com/docs/reference/fql/event, it says this:
Permissions
To read the event table you need:
a generic access_token for public events (those whose privacy is set to OPEN)
a user access_token with user_events permission for a user who can see the event for non-public events
an app access_token with user_events permission (for non-public events, must be the app that created the event)
a page access_token with user_events permission (for non-public events, must be the page that created the event)
I am not looking to get help with the code really, I am just having trouble figuring out how the access/auth process works.
It appears FQL may be the best option so I can do queries based on date ranges, but alas, I am stuck on the access/auth/token part.
What do I need to have in place to be able to list a Page's events on a 3rd party site?
If anyone has any advice there, I would appreciate it. Thanks.
Just to explain to others, you cannot get ALL the events in the city by graph search. You need to refine it either by user details or some other metric.
I figured it out.
This question helped, but was not correct and there is a syntax error in an answer:
Get Facebook events from public fan page
From what I found, you need to become an FB developer, create an app, get an ID and secret.
Use the SDK (PHP in my case), and this question had a good example of returning the list I want:
Link from ticket_uri is opening a blank page
I am having the same issue though of getting blank pages on the ticket link if the user is not logged into FB.
But my original issue is solved.

Where facebook saves an infomation about registered users?

I am trying to integrate my site with FB. So I have begun with registration plugin. My question is: where FB is saving the registered data, because when I am already registered on my site via FB registration plugin and viewing registration form again FB informs me that I am already registered. I could not find any information about it in user profile or in my app panel.
Thx for advise. If something is not clear I will be glad to explain my problem once again.
Check out the signed_request that Facebook is sending to your app via the redirect_uri (which is a page somewhere within your Site URL). It will have the encoded information for that user.
When you say "integrate my site with FB", I assume you mean "let people authenticate on my site by authenticating on Facebook ?".
I think there is all the info there :
https://developers.facebook.com/docs/guides/web/#login
https://developers.facebook.com/docs/authentication
EDIT : regarding the "http://developers.facebook.com/docs/plugins/registration/" example ; I can not say it authoritavely since I don't have the code, but I think what happens is that :
The registration form is in a iframe, showing a page that is generated on the server side (maybe, your server)
If you are not logged in, the form is not filled
There is a "login with facebook" that opens a pop-up with a page (from Facebook site) that has an extra param called "redirect-url" ; this will be a url or your site
When the user enters it's credentials, on the registration form that is posted to Facebook, they check the username/password, and when done, they call the "redirect-url" (again, a URL from your site) and pass the info in this (in this case, the redirect is configured to get a number of fields (name, birthday, location, etc...)
Your site gets the info in the form of a "signed_request" (see the section "Reading the Data"). In this case, it will render the same "Registration" page, except I would guess that on the server-side, some fields have been filled with the info provided by FB's signed_request.
The trick is that in this example, everything happens in an iframe - I'm not sure how this is mandatory.
Now, about the question "If I am already logged in FB, and I go to the Registration form, how does my info get in the form ?", I can only suppose that FB sets a number of cookies when you log in, that client site can use - but I agree with you that the documentation is not extremely clear about that. Probably, it's suppose to be hidden by FB's API, but the doc does clearly point to which one (at least on this page).
Again, I'm just speculating from the doc and tinkering with the requests made on the pages (and experience with similar oauth-y authentication schemes) ; hopefully someone with an actual application can give you more info.
Hoping this helped - sorry if it did not. Good luck with your dev.
PH