Facebook API - Multiple actions - 1 API Request - php

so i searched here and there yet i couldn't find anything except the outdated FQL that's gonna get limited or removed ( not quite sure ). So i'm building a app and i want to make it to post in let's say all the friends's walls but i don't wanna use a for loop because that will eat the host's CPU like a mad dog. My question is can you suggest a method ?
What I currently got:
Long lived tokens
JQuery + PHP login

Let's clarify a couple of things here:
Facebook Query Language (FQL) is not outdated and as far as I know, there are no plans to deprecate it!
Posting to friends wall is going to be removed in February 2013
Facebook always recommends using user-initiated sharing models instead of automating the process.

read about the Batch Requests concept here:
https://developers.facebook.com/docs/reference/api/batch/
this will enable you to make multiple graph API calls at once
but, this is extremely not recommended to make 1000 calls with it, and it probably won't work at all because you will easily reach facebook's call timeout.
FQL will be a better method in this case because you can do it in one query (with start and limits)

Related

How does Facebook notify and instantly shows new comments or how does Stackoverflow do it?

I am a PHP developer and the title basically says it all. However I was hoping on some more in-depth information as I am starting to get confused about how the flow for the project I work on should go.
For an (web) application I need to implement a feature like Facebook does it with notifying users about replies/comments and instantly showing these.
I figured I could use long-polling with ajax requests but this does not seem to be a nice solution as the notifications never really are instant and it is resource heavy.
So I should use some form of sockets if I understand correctly, and Node.Js would be a good choice. So based on the last assumption I now get confused about the work flow.
I thought about two possible solutions:
1) It seems to me, that if I would use Node.Js I could skip using PHP at all and base the application on Node.js only.
2) Or I could use PHP as a base and only use Node.js for notifying users and instantly showing messages but saving the data using PHP and Mysql.
These two possibilities confuse me and I can't make up my mind about what would be the "best" and cleanest way.
I do not have much experience in Node.js, played with it for a while. But managing and saving data seems to be hard in Node.js so that is why I came up with option 2.
I know Facebook is build on PHP so I am assuming that they save the data via PHP and notify / instantly show replies and comments via Node.
Could someone help me out on this?
Thanks in advance!
EDIT:
I just noticed, Stackoverflow does something similar. I get a notification in the upper left, and below my question a box with "new answer to this question". I am really interested in the technologie(s) used.
Well you could use node.js for the notifications and PHP for your app.
By googling I found this about real-time-notifications.
You could also just use node.js with socket.io, but this means that you have to learn new technologies as you mention that you have no experience with node.
I haven't used it but you could check this project, for websockets in PHP.
When you have an update that you want to notify users you can use the publish subscriber pattern to notify the intrested in this update.
Take a look in Gearman too.
Personally, I've built a notification system using the pubsub mechanism of redis, with node.js+socket.io. Everytime that there is an update on a record then there is a publish on the appropriate channel. If the channel has listeners then they will be notified. I also store the last 20 notifications in a Redis list.
The appplication is built in PHP. The notification system is built in node.js. They are different applications that see the same data. The communication occurs via redis. For example in the Facebook context:
1) A user updates his status.
2) PHP stores this to the database and Redis
3) Redis knows that this update must publish to the status channel of the specific user and it does.
4) All the friends of the specific user are listening to his status channel (here comes node.js)
5) Node.js pushes the notification in the browser with socket.io
As for facebook, I have read in an article that is using long polling for supporting older browsers. Not sure for this though, needs citation...
AFAIK It would be via two simple methods :
First one that could be very simple is adding a Boolean column to each record that determines if it has been notified or not.
The second method is creating a table to insert all notifications.
However, I'm not sure if there are alternative methods for better performance, But first method is what I do commonly myself. But I think Facebook is using 2nd method, because it has to notify each one to a lot of users.
Your question maybe dublicate of:
Facebook like notifications tracking (DB Design)
Database design to store notifications to users
You could use Server Side Events it involves a bit of JavaScript but nothing overly complicated I think.
The main bulk of this method is PHP though, so you would just use the PHP to query your DB for notifications and SSE will push them to the user.
It does have some limitations though, most notably it's not supported by IE (huge surprise) thought i'd mention it anyway to let you know of other possibilities.
Hope this helps

Appmobi Codeigniter and Facebook SDK JavaScript vs PHP

Ok, this isn't going to be the best quality question without a doubt. But I am looking for advice mostly on how to handle the next phase of an app I am developing. This is my first app in appmobi so things with it are a bit confusing to me still.
So generally speaking I am very used to working with PHP and sticking to browser based development. With that most of what I want to do with Facebook as far as the API's go for the graph I have done using the PHP FB-SDK. If your familiar with Appmobi then you know php is out well directly at least.
This app I am making, I have it working fine with everything else I am doing. I'm communicating with my server, people are logging in, people are registering, people are using the server for what its worth. But this Facebook bit has me stumpped. I want to offer facebook as a means of login/registration for my app, I want to post to facebook from my app pending a user approves it, and a handful of other things. But I dunno the best way to approach this through the app as its all static html based pages and javascript thus far.
So I am hoping someone will read through this all, and hopefully a handful of you that do, will know some means of doing what I want to do, Im not looking for someone to drop me a pile of code and give me the answer (nice as that would be). No I am just simply looking for what I should do to handle this between all the layers mentioned here to make this work. So I can start building this piece up.
Regarding Facebook, appMobi has recently added a Facebook object to the API you might use to be able to log into Facebook and access the Facebook Graph. You can find the Facebook API documentation here:
http://www.appmobi.com/documentation/jsAPI/facebook/index.html
There is a supporting document illustrating how to set up things on Facebook's side that can be found here:
http://www.appmobi.com/documentation/index.php?DOC=FACEBOOK_INTEGRATION
I'll do my best to post some sample code as well. I'm kind of working through the exact same thing.

Is the Facebook Graph Api fast enough? (PHP SDK)

At the moment I'm working on my first website with Facebook Graph functionality, so I'm new to all this. I'm using the PHP SDK in combination with Javascript SDK.
I'm wondering, is calling the Facebook API fast enough to deliver userdata such as id/name/picture etc. or should I retrieve the data once after login and save it in my own database or a session or something like that?
that usually depends on your own definition on "fast".
Once I have done a project, the page transition take usually 1.5 sec. To me, that is acceptable...
how, client expect it to be 0.5 sec.
Just in case you find the performance not acceptable, you can consider to add a caching layer in your app to speed things up.

Real time activity feed - code / platform implementation?

I am defining out specs for a live activity feed on my website. I have the backend of the data model done but the open area is the actual code development where my development team is lost on the best way to make the feeds work. Is this purely done by writing custom code or do we need to use existing frameworks to make the feeds work in real time? Some suggestions thrown to me were to use reverse AJAX for this. Some one mentioned having the client poll the server every x seconds but i dont like this because it is unwanted server traffic if there are no updates. I was also mentioned a push engine like light streamer to push from server to browser.
So in the end: What is the way to go? Is it code related, purely pushing SQL quires, using frameworks, using platforms, etc.
My platform is written in PHP codeignitor and DB is MySQL.
The activity stream will have lots of activities. There are 42 components on the social networking I am developing, each component has approx 30ish unique activities that can be streamed.
Check out http://www.stream-hub.com/
I have been using superfeedr.com with Rails and I can tell you it works really well. Here are a few facts about it:
Pros
Julien, the lead developer is very helpful when you encounter a problem.
Immediate push of new feed entries which support PubSubHubHub.
JSon response which is perfect for parsing whoever you'd like.
Retrieve API in case the update callback fails and you need to retrieve the latest entries for a given feed.
Cons
Documentation is not up to the standards I would like, so you'll likely end up searching the web to find obscure implementation details.
You can't control how often superfeedr fetches each feed, they user a secret algorithm to determine that.
The web interface allows you to manage your feeds but becomes difficult to use when you subscribe to a loot of them
Subscription verification mechanism works synchronous so you need to make sure the object URL is ready for the superfeedr callback to hit it (they do provide an async option which does not seem to work well).
Overall I would recommend superfeedr as a good solution for what you need.

Simple way for read only twitter api usage

probably like many people my site has been affected by twitter deprecating basic authentication, so I was looking at implementing OAuth. But all I want to do is just pull the last couple of tweets from my account - I don't need to post anything, it's just readonly access to the user timeline. I've seen a couple of posts showing how to do this easily with javascript, so i'm thinking it might also be similarly straightforward with PHP (i.e not requiring OAuth)? One reason for having to use PHP instead of Javascript is that i need to check when the rate limit is about to be exceeded, then I cache the last couple of tweets for the required amount of time.
If OAuth is the best solution, I'll get on with that - grateful for any suggestions though!
I wrote a article showing how to do this:
http://philsturgeon.co.uk/news/2009/07/How-to-Create-a-Twitter-feed-with-full-syntax-support
but the basics are even easier. It all boils down to:
$tweets = json_decode(
file_get_contents('http://twitter.com/statuses/user_timeline/philsturgeon.json?count=10')
);
Enjoy.

Categories