Combine Facebook and Twitter Searches - php

I am making search requests to both Facebook and Twitter using an iPhone application, my issue is I require to combine the searches into a single view, so to go about this I intend to make a request to an individual script on my server, which will then make the requests to both Facebook and Twitter, decode the JSON results, combine them, order by date and then output once again in JSON. This JSON will be fetched by my iPhone application, decoded and placed into a table view.
Whilst I have the client side part sorted, and am capable of making requests in PHP to obtain Facebook and Twitter search results, I have no idea how to combine them and order by date, given that the JSON keys/entities for Facebook and Twitter are different. They don't both use the same key for date, for example. How would I go about doing this?
Some code examples would be great.

Is there something preventing you from creating your own data object or storage method with a way to parse a Facebook or Twitter result into it? If both results have different keys for the date as you say, you would just translate it into something you can parse.

Related

Going deeper into facebook's graph: collecting friends available data

I am building an PHP website using Facebook Graph API's and I can only read and collect very basic data.
I managed to collect the one-line informations from my profile:
Ex:
$user_profile['hometown'];
$user_profile['bio'];
$user_profile['name'];
$user_profile['id'];
printscreen 1: http://postimg.org/image/fsj6w4dtz/
First of all, I want to collect for the current user logged in, the education data for example:
*how should I collect this data, because $user_profile['education']; it is not working? What do I have to do if I want to collect informations about the users education (such as school, year, class-mates, type?)
printscreen 2:
My main focus is finding a way to get for the current user loggedin, all of his friends data (such as name, events, bio, birthday, everything they let me to :d)
*I've googled and read part of the facebook API's docs but I dont really understand how to do this. I know this is possible, because I have tested with this tool: developers.facebook.com/tools/explorer/?
printscreen 3:
** below is a image of trying to read the friends's infos, but for sure its wrong (anyway it doesnt work): postimg.org/image/4dg8khj77/
I think you are struggling while accessing the object that the API returns. Facebook PHP API returns the decoded JSON object and therefore you must understand how to access data in a JSON decoded PHP object. Have a look at this thread to see how you can do that.
Therefore, in this case, you can simply access the deeper levels of a decoded JSON object by doing something as: $user_profile->education->school->name

PHP twitter Hometimeline

I making a php server/page which is supposed to capture a users twitter feed and then provide it in a JSON format to another application and/or mobile device in JSON format.
Twitter provides it's data already in JSON format by using .json after the timeline url. But this is limited to 150 requests/hour which can be a problem being on a shared hosted server.
If been trying to use the twitteroauth php library with API keys. Before I can start communicating with the API I always need to sign in with a twitter account. Using the API is limited to 350 request/hour.
Is there a way to use the library not needing to log in to capture the timeline?
Or what is a better way to achieve my goal, creating a php-page providing me the timeline on request?
If I understand the question correct, the problem is that you make to many request to the Twitter API that doesn't require log on. In that case, if you don't want to use the API that require login, I guess you could implement some caching. Let your server run a cron every minute that check the Twitter API for new tweets, and store the tweets in a database or a textfile.
Then, when a user request your page for JSON, you read from your cache instead of going straight to the Twitter API every time. That way you will save a lot of traffic between your server and Twitter, and you would still be very close to real time when it comes to up-to-date tweets, as you with 150 requests/hour could update your cache every 30 seconds or so.

how to get feed links i.e. .rss .xml etc from google feed API

I want to use the Google feed API to search for news feeds however i don't have any previous experience of using an API so i was thinking somebody can help out about building an application where users can enter their query and get the corresponding feed/feeds matching it.Basically my emphasis is upon getting the feed links.
The Google Feed API is typically accessed using a REST with JSON interface. Meaning you make requests, similar to how make requests in your browser using the address bar, and it returns data which is normally in JSON (Javascript Object Notation) format.
As an example, try putting this into your address bar:
http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=&q=http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml
It uses the Feed API to return front page news from BBC. Now, javascript isn't the only way to do access the API. Using the same method of connecting, in PHP you could use something like:
// Create REST request URL
$url = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=&q=http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml";
// Make request and get resulting JSON response
$json_feed = file_get_contents($url);
// Dump it to the screen so we can see it
var_dump($json_feed);
You can return results in JSON, XML, or Mixed and using PHP can then use the data for any processing you may need to do. If you are using Zend Framework or are familiar with implementing any of their components, they have the GData component which is a PHP library for accessing Google Data APIs.
For more information, check out the Feed API's Developer Guide.

How to search Twitter?

I need a PHP script that uses the Twitter API to obtain the following information: the number of unique tweets (or status updates) from a specific user (using their twitter username) containing a specific hashtag during a specific period of time.
I need that value to be the only returned data from calling that function/script; as well as the customizable lines of code containing all relevant values that I need to fill (app id, secret, username to obtain info from, etc).
Zend Framework has a nice Twitter API lib, which can be used standalone:
http://framework.zend.com/manual/en/zend.service.twitter.html
This is very simple to do with Twitter's Search API.
This is a JSON feed (just fetch with cURL or file_get_contents() and parse with json_decode()) of my Twitter posts that include the #fb hashtag: http://search.twitter.com/search.json?q=+%23fb+from%3Aceejayoz

Selecting specific fields with facebook graph api

I'd like to fetch statuses from users facebook newsfeed via the graph API.
It seems to be pretty simple when I have the right access token, then I can fetch this data with http://graph.facebook.com/home... But I want to fetch only statuses; no links, photos, videos and so on..
On the documentation page, I've seen many possibilities to specify selected data, for example I can limit obtained count of posts. Is there any possibility to control which data will be particularly fetched and which not? For example like graph.facebook.com/home?type="status"..
I can classify it in my PHP script, but then I need to be able to fetch a few more posts, like when I click on the more button on facebook or twitter, etc..I see some pagination data in Facebook JSON(I hope it's JSON:)), but I am propably not capable to use it in right way..
Thanks for your help!!
The doc page http://developers.facebook.com/docs/api says:
The Graph API allows you to read properties and connections of the Facebook social graph. You can use the API to read specific fields, get pictures of any object, introspect an object for metadata and get real-time updates on any changes.
...and...
You can choose the fields (or connections) you want returned with the "fields" query parameter. For example, this URL will only return the id, name, and picture of Ben: https://graph.facebook.com/bgolub?fields=id,name,picture

Categories