Add users post to their facebook newsfeed automtically with php - 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..

Related

How to get the "publish_post" equivalent

Scenario
I'm building an application that needs the ability to post to users wall (personal profile) on behalf of a user on facebook. I remember before the way that I would do it is request a permission "publish_actions" but reading through their documentation i came to this page:
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes/#login-4-24
which states that that is being deprecated.
They recommended an alternative which is using their sharing product found here but this seems like it would break one of the functionalies of my current application (I dont want to share content i want users to post it to whenever they choose to on whichever account they choose to).
Question
Is there a way to get posting to a users wall and NOT an event, page or group. If i'm correct I can still post data to events, pages and groups via API as normal but to a users wall its different? I need to post on their wall via api but i can't seem to find the permission.
My facebook api graph version for my app is 3.0 and im using their PHP SDK to make the requests.

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

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"

Easy way to get facebook statuses from a particular page in PHP?

I need to grab the statuses from a Facebook page via PHP to display on the page. I don't want to have people logging in to facebook just for my script to grab the statuses from the page since it is a public page and isn't restricted. I have the Facebook API for PHP in my projects directory but have no idea how to use it to do what I want it to. Could someone give me a code example of how I'd do this? Thanks!
It's really a straight forward task if you follow the documentation. Since /PAGE_ID/feed requires any valid access_token, your app access_token is enough to get the data:
Open the Graph API Explorer (I'm querying coca-cola/feed)
Get an app access_token from the Access Token Tool and use it instead of yours
You're done!

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.

Posting to User's walls as application using Facebook PHP API

I've been building a web app that uses facebook integration for easier registration/login and notifications for the users. However, for the notifications I want to be able to post to a users facebook wall when something happens on our site.
Really I see two possible problems with doing this. First being that the user will most likely not be logged in to our website when the notification needs to happen. Second I have not found a way to post to the feed using any identity other than the current logged in user.
So to reiterate exactly what I'm trying to do. When some action takes place on my site involving Bob, I want the websites application to post on Bobs wall notifying him of the action as if the application is one of Bobs friends. From some of the things I've seen while researching this, it seems as if facebook might not treat applications like users and I might have to go through a page to accomplish what I want. But really I'm ok with that.
What you need to do is to ask for the offline_access permission. Then you can store their graph id property after they login/authorize to your site's database. Then you just post to that graph id instead of instead of /me. In your case you would then POST a request to the "$user_graph_id/feed" endpoint with whatever parameters you usually have.

Categories