Facebook Open-Graph API Subscription or Update Notification without App Permission - php

I'm relatively certain after reading the facebook Open Graph documentation that I can't have a web site 'subscripe' to a public page, unless that page installs my app. Let me know if that is wrong.
What I am trying to make is a photo gallery, pretty simple, but it grabs photos from a public 'page' such as a college or university.
I would like it to update itself anytime there is a change. I was hoping I could do it through the API, possibly using API updates/subscription
Facebook App Subscriptions -
but I don't think that will work. I'm using PHP, are there other ways to listen and see if there has been a change? Other than just firing off a function every now and then, using CRON or some other such server tool. I would think that facebook would probably also not like that behavior, though I'm not sure.
As of right now, I am able to grab JSON from a public page's photo gallery using the API and the photo gallery works just fine, I'm mostly just wondering what the optimal of having it update itself automatically is.

You are correct in assuming that real-time updates for pages require admin access to the page to work. You need a page access token to be able to subscribe to updates for a specific page, and such a page access token you can only get from users that have admin privileges for that page. (The page does not need to install your app as a tab any more, they changed the subscription process in that regard; but the page access token is still necessary. Basically you can say, you can not subscribe to updates for just any arbitrary page, it has to be “your” page.)
Apart from that, all you can do is check for new content by requesting the current data in a sensible interval.

you need to get page access token, which is granted when the user is one of the Page Admin, check the documentation on Facebook
https://developers.facebook.com/docs/graph-api/reference/page
look for this line
"access_token": "The access token you can use to act as the Page. Only visible to Page Admins"

Related

Add users post to their facebook newsfeed automtically with php

I have a website I'm working on. It enables users to register and post stuffs within the site. Can I get a link to some sort of api that allows people to add their facebook account (once) and then automatically post what they posted on my site on their facebook newsfeed (the sort of thing that happens when you connect your facebook account to your twitter account) .I've searched and can't seem to get exactly what I want
What you want is pretty common and if you searched you clearly didn't do a good job on the search.
Using the Facebook PHP SDK is pretty straight forward. There is a PHP Library available with a demo of the functionality you want. In your case you need to do some stuff more, so I'll explain globally what you should do:
Get the Facebook PHP SDK and load it into your website, determine what scope you need to perform the actions what you are going to do, in your case you need to have access to their timeline which is called the publish_stream scope. In order to get the Facebook PHP SDK working you need to create an app at http://developers.facebook.com
If a user grants access you need to save the authentication token that the user provides and save it in your database for later use. I'm not 100% sure how long they are valid, I think it's maximum of 30 days at the moment, but you have the ability to refresh the toking in the requests you make (correct me if I'm wrong, it's been a while..)
Everytime an action is done using the Facebook API you inject the usertoken in the request, thus performing the "post" action onto their timeline.
What you are looking for is pretty straight forward and easy to find..

Get facebook posts/events/news/gallery with javascript (or php) inside my website

I'm tryin to develop a (almost) 100% client-side dynamic website by integrating it with twitter, facebook and flickr.
I've been able so far to get the last 4 tweets (with javascript) from my client's feed, and now i was wandering if i could do the same with facebook's gallery and events from their feed.
Especially, what i need (given the facebook username/api key/whatever)
gallery
for each gallery in user's profile:
get the gallery name
get the first picture
get the gallery url
news/events
for each news/event/post in user's profile:
get the event name
get the event text
get the event picture (if provided)
get the event url
I don't want to use the facebook widgets with their rendering, i just need to read the json response (if there's any) and put the data inside my website (like a preview).
Since my client is pretty rusty with "computers (cit.)" but he's (not so strangely) comfortable with facebook/twitter/flickr, i tought about a solution like this before adding a database and an admin interface to our website.
I found some resources online, so i think it's possible (in a way or another). I'd like to do it in javascript, but if it's php i won't complain.
Check out this API to get photoes from the user profile
http://developers.facebook.com/docs/reference/api/album/
This is for events
http://developers.facebook.com/docs/reference/api/event/
You can use either the PHP or the Javascript API SDKs:
http://developers.facebook.com/docs/reference/php/
http://developers.facebook.com/docs/reference/javascript/
respectively. Naturally you would handle the returned information differently. Both have a method called api() which can be utilised to grab the album and event objects (as mentioned in another answer):
http://developers.facebook.com/docs/reference/api/album/
http://developers.facebook.com/docs/reference/api/event/
You can pass parameters in the methods to restrict the results returned by fields, number of items, sizes of images etc. This is outlined here:
http://developers.facebook.com/docs/reference/api/
But the issues you are going to face is that you have to authorise your "app" - think website when they use the terminology "app" - to give it permissions to access the information. This takes the form of a two step process. You have to create the app on the Facebook platform which can then access the API methods (only certain information can be got from the API methods without an authenticated app).
The second part is that the user themselves must then authenticate their facebook account against your app - this gives your app permission to access the user's information. In plain English it would go like this:
User visits your webpage; user must be logged into Facebook and must approve your app (this used to be called Facebook Connect for obvious reasons); the app and the user account are "connected"; the app can then use the api methods you've written to return information about the connected user
The beginning explanations of how to do this are here:
http://developers.facebook.com/docs/authentication/
The only way you can access a user's (non-public) information from outside of Facebook is via a connected app and user profile.

Pulling Public Facebook Posts Into PHP Page

Last December, I set up an app for a client who wanted to pull their public facebook posts into the footer of their website.
I was using this URL to pull the message, create time and permalink and when I wrote it, all was good:
http://api.facebook.com/method/fql.query?query=SELECT%20message,%20created_time,%20permalink%20FROM%20stream%20WHERE%20source_id=138631878804%20AND%20message%3C%3E%27%27%20limit%203
Today they reported that it was no longer pulling their information. I put that url into a browser and the result is "Requires valid signature"
I've gathered from google that I need something called an access_token, also I've seen where I can use the php sdk but then I need an appId and a secret token.
At this point, I've read so many different sources that I am thoroughly confused. The FQL query above represents the full extent of my Facebook programming experience. It looks like maybe I want the Graph API, but I don't want anyone to have to sign into anything.
Can one of you guys who are more versed in the voodoo of facebook nudge me in the right direction to do this:
From PHP, pull public messages from the stream table without forcing a user to log into facebook.
Thanks!!
To pull posts from a publicly visible Page on Facebook, you can use any valid access token. For most sites managing a page, this will be a page access token retrieved via one of the page's admins authorising your app to have access to their pages, but that might be overkill for your use-case.
Probably the quickest solution is to just create a new App ID for the site, get the app access token for that App (see 'App Login' on https://developers.facebook.com/docs/authentication/ ) and then use that access token to retrieve the posts.
I found several links all from a simple Google search.
Duplicate question: https://stackoverflow.com/questions/3298836/how-you-get-access-tokens-for-facebook
http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
https://developers.facebook.com/docs/authentication/

How to programmatically "press" a 'Like' button through a Facebook Application?

I'm developing this Facebook Application and I was wondering if it's possible (and how) to programmatically, through the Facebook PHP Graph API, press some 'Like' button on some page?
Of course, this is optional on my application... I'm still not ready to really explain what application I'm doing, but it would be interesting to code such a feature.
Is it possible somehow?
By your description it sounds like you're trying to get a user to like something without the users knowingly clicking a like-button. This sort of interaction is not condoned by Facebook, I think. There are various black-hatty ways to accomplish this though, one fairly elaborate one is descriped here: http://www.liquidrhymes.com/2010/08/25/smoking-hot-bartender-is-some-smoking-hot-facebook-spam/
UPDATE Sorry, I might be wrong. If you get stream_publish extended permissions from the user, you might be able to like posts on their behalf by doing a POST to /POST_ID/likes. See Publishing to Facebook in http://developers.facebook.com/docs/api
You cannot do this. Facebok wont let you do a POST to /POST_ID/likes, you can only do a get request to retrieve their likes. What you are trying to do is a violation of facebook's TOS. I would suggest just adding a like button and "forcing" them to like before they continue with your application. However, in my opinion even that is kind of silly because they can instantly go unlike it after they have used your application.
i was looking for the same thing, but not to force a user into liking something, but actually for their own protection.
here is where i come from: on a web site (maybe on multiple pages) there is an "I Like" button, implemented as described by facebook.
each time a user goes to that page, the browser will make a request to facebook, throught the iframe that contains the button, providing all the info that we are used to from a web server log file.
if the user has in the past logged in facebook and not cleared the cache. the request will also contain the cookie indentifying the facebook user.
so even more then analytics, facebook know all about the user activity on those pages.
so i wanted the user to only give this info when they decide to.
my solution was to have a button (as graphic only) on the page. when the user clicks it a new frame should open and only there the facebook code should be executed.
obviously on the new frame i could not put the normal "i like" code, since that would require a 2nd click for the user. at this point i would need the "programmatically clicking of the i like button".
it is not an opengraph solution, but it works: the frame just does a redirect to
http://www.facebook.com/share.php?u=URL

How can I build an API in PHP

Hello I am looking to build a basic API and application/apps system on my social network something like Facebook or other sites have, my site is in php/mysql. Here are some questions.
1)
Basically what I want to do is give a user a API key and secret. After I have these how can I use them in my php app to authenticate a user request which would come from there server?
2)
I can basically build an API to send a request to my server with CURL and get the result back to the page in XML or JSON or whatever, the problem is when sending the request the user would have to know the user ID they want to send to lookup data against, this is fine for an API but I am wanting to have an Apps section where the user's app site would be using the API and would be loaded into my site in the app section with an iframe, the problem is, I need to find a good way to make it where a logged in user on my site can go to the app section and go to an app and there username should be available to that page loaded in the iframe. Facebook and myspace do this somehow and many other sites; I am lost how to get around this hurdle.
Any help on any of this is really appreciated, thank you
Update:
I just had an idea, if I require a cookie to be set when a user visit's my site, then they would have a cookie and it could hold there User ID, then my API script could look for that cookie to exist and grab it's value?
If you plane on using an IFRAME, then no, your API hosted on a separate website (the website inside the IFRAME) would not be able to grab the cookie. The cookie is only visible on the website that it was set for.
I have only used Facebook API with the FBML (not the IFRAME,) but all they do their is basically replace what's in the page with the info that the "tag" is calling. I'm not sure if there is a better way, but you could possibly call a page on the app's server (say the app is hosted at http://example.com/app/, and you called http://example.com/app/?id=28318&name=John%20Maguire,) and have your API code handle it and turn it into a variable?
Maybe you should look into the source code of the Facebook API client.

Categories