user_timeline twitter API problem - php

I'm using http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses-user_timeline to read the tweets of the user. When I used basic auth, it worked fine. When I switched to OAuth, the 'page' parameter stopped working.
Like so:
http://api.twitter.com/1/statuses/user_timeline/16.xml?count=25&page=2
When I use OAuth to fetch the request, it always returns the first page. I check my code. I even echoed the exact same line, and it was exactly what I needed. The XML is exactly what I want, but when I use OAuth to fetch the XML, it returns the wrong XML.
I use abraham's php library.
So basically. The XML is correct and when entered as URL it returns the correct XML, but when trying to fetch it through OAuth, it returns the wrong XML.
Any clue?

In the latest version of my library (currently 0.2.0-beta2) it should be called like this:
$to->format = 'xml';
$content = $to->get('statuses/user_timeline/16', array('count' => 25, 'page' => 2));

I just encountered the same problem - when i am using oauth, Twitter seems to be oblivious about GET parameters. I am using php lib form here: http://abrah.am
this doesnt work:
$url =
"http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=$name&count=199&page=1";
$content = $to->OAuthRequest($url);
but this does:
$url = "http://api.twitter.com/1/statuses/user_timeline.rss";
$content = $to->OAuthRequest($url, array('screen_name' => $name,'count' => 199, 'page' =>1), 'GET');

Related

how to use GET to obtain info from a URL

I'm a php programmer but I'm new to APIs.
I would like to run a mysql query to get info from an XML document from madmimi.com.
documentation from madmimi.com says
GET http://madmimi.com/audience_lists/lists.xml will return the data I need. I've created a php file and connected to their API using
require(dirname(FILE) . '/MadMimi.class.php');
$mailer = new MadMimi('username', 'password');
but I don't understand how to use GET to connect to the URL and display the XML info?
What do I need to do?
All http api interaction is hidden to you behind their library. You can use it's methods to grab objects, like this to lists:
$mailer->Lists();
There is no complete documentation, but you can read raw code to search urls, described in API for finding appreciated methods.
You can use curl to get the response from the 3rd party api. Have a look at this answer:
https://stackoverflow.com/a/5159513/1369567
Based upon the code in answer given at that link, you may need to the code to match your request. E.g:
/* Script URL */
$url = 'http://madmimi.com/audience_lists/lists.xml';
/* $_GET Parameters to Send */
$params = array('username' => '*your api username*', 'password' => '*your api password*');

Google Play scraper

I'm trying to develop a Play Store reviews scraper in PHP and I need to make a POST request to this URL https://play.google.com/store/getreviews, and I saw the parameter post with firebug.
I am using Goutte library and here is my code:
require_once 'goutte.phar';
use Goutte\Client;
$client = new Client();
$params = Array(
"id" => "com.trello",
"pageNum" => 2 ,
"reviewSortOrder" => 2 ,
"reviewType" => 0,
"xhr" => 1
);
$crawler = $client->request('POST' , 'https://play.google.com/store/getreviews', $params);
The problem is that the request returns nothing. Is there anyone who already faced this problem and solved it?
I don't think this is possible. Google Play changed their review interface last year. They now have a "token" parameter which is missing here. I have worked before to try and work out what seeds this (see Google play review scraping changes) but I can't figure it out. After a number of attempts to hit that webservice with an incorrect request (presumably without the token) Google Play starts blocking your IP, that's why you'll be getting nothing back after a while (and won't be able to open Google Play in your browser either). If you find a solution, let me know!
This URL works for me, with the form-post data in your example.
https://play.google.com/store/getreviews?authuser=0

trying to fetch user tweet stream in php

I am using the following code, but it showing a 404 error
$url = "http://api.twitter.com/version/statuses/user_timeline.json";
$call = file_get_contents($url);
There's no 'version' version. The Twitter API is currently version 1, so you need http://api.twitter.com/1/statuses/user_timeline.json.
Do note that Twitter can't read your mind, so you'll need to tell Twitter which user's timeline you want to fetch... i.e. http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ceejayoz

Get Flickr Sets

Usual stuff, Googled forever, looked on here, no help. Yet.
What I want is to list the sets of photos I have on Flickr. Nice & simple, it would seem.
I want the 'title image' (the one used as the thumb for it on Flickr its self), the title and URL. Can't be that hard, can it?
The language of choice is PHP (5.1.6), or JS (jQuery if possible). Both are good.
Using flickr.photos.search method of the API with your user_id does not work ?
For PHP, you have a PEAR-based package here and another library at http://phpflickr.com/. Should be enough to get through it.
EDIT :
For minimal implementation you should use stream_context_create() with HTTP headers, use fopen() with this context and build a XMLRPC request by hand as a text variable that you will send. Answer from the socket will be your data
For the API, use flickr.photosets.getList
CODE EXAMPLE (you need a valid api key for flickr)
<?php
$apiKey = '';
$userID = '';
$url = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key='
.$apiKey.'&user_id='.$userID.'&format=json';
$options = Array('http' => Array('method' => 'GET'));
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$object = json_decode($response);
see also http://framework.zend.com/manual/en/zend.service.flickr.html for a nice tidy wrapper

Specifying Parameters in Zend_GData when using an Oauth Token?

So, I figured out how to get an access token from Google using the Zend_Oauth library in 1.10. Now lets say I want to get my contacts...
$config = array(
'consumerKey' => 'zzz',
'signatureMethod' => 'HMAC-SHA1',
'consumerSecret' => 'xxx'
);
$token = unserialize($_SESSION['GOOGLE_ACCESS_TOKEN']);
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
// $client->setParameterGet('max-results', '10000');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
// $query->MaxResults=100;
$feed = $gdata->getFeed($query);
$feed is a lovely object with 25 contacts. But if I want to get more in a single pull, there doesn't seem to be a way of specifying max results that works.
If I uncomment client->setParameterGet it's ignored. It works if I specify $client->setUri and use $rawdata = client->request() to get the response, but then other issues crop up with handling the feed data that comes back... like getting it into GData for easy handling.
I've tried $feed = $gdata->importString($rawdata->getBody()) but while $rawdata->getBody() returns what seems to be valid XML, $feed->totalResults throws an error, while it wouldn't if I used $gdata->getFeed($query).
If I uncomment $query->MaxResults=100; use $gdata->getFeed($query) Google returns a 401 with "Unknown authorization header".
So is it possibly to specify parameters while using Zend_GData with an Oauth token? Or am I going to have to build my own requests, then use Zend_Feed (or some other XML/Feed dissector) for parsing?
I totally cannot get the whole list of contacts only 25... parameters do not seem to work using Gdata and query like this:
$http = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata($http, 'MY APP');
$gdata->setMajorProtocolVersion(3);
$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full?max-results=10');
$query->setMaxResults(10);
$query->maxResults = 10;
$feed = $gdata->getFeed($query);
so i;m really into finding answers here as well. If either of you gets anything working. please post :-)
thanks
It's a bit tricky mixing a process meant to work with AuthSub with OAuth. I did some digging. So far I can get it to download all my contacts like this...
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
$client->setUri('http://www.google.com/m8/feeds/contacts/default/full/');
$client->setParameterGet('max-results', '10000');
$client->setParameterGet('v','3');
$bfeed = $client->request();
Looks like the primary difference between us is I specify the Feed URL in the $client->setUri('http://www.google.com/m8/feeds/contacts/default/full/'); and set my version differently. But I can get the body() property of $bfeed and it gives me 245k of XML to dissect.
My problem is that when I'm pulling down a single contact's feed via this method, I was getting an error.
I, like you, am trying to figure this out, so please reply with anything that works for you.

Categories