For those of you who might be able to help out, but don't feel like reading the whole post: i'm looking for a working example - including OAuth authentication - that can fetch me twitter user-timelines using the new v1.1 API from twitter and using ZendService/Twitter. Furthermore, i want to use application-only-authentication <https://dev.twitter.com/docs/auth/application-only-auth> (so it is not necessary for users to to interact)
---------------------- For those of you interested in what i've tried so far, read on. I'm running into multiple problems trying something so easy as getting a feed of public tweets from various twitter-accounts. >From what i understood on the twitter website i had to use application-only-authentication <https://dev.twitter.com/docs/auth/application-only-auth> I've configured composer.json as follows to include zendservice/twitter: /"zendframework/zendservice-twitter": "dev-master" / this, in turn, also includes zendoauth:/ "zendframework/zendoauth": ">=2.0.0"/ (just so you know which versions i'm using) The first problem really is all the outdated documenation that is still online. But well i won't get into that now. So, reading the docs i understand i must first authenticate using ZendOAuth (the documenation says this is not necessary for public timelines, but it's one of those things that is not correct in the documenation - _all_ api calls must be authenticated) After reading the getting-started document (which was not sufficient) and various other pages on the internet i was able to able to piece this together: $config = array( "consumerKey" => "[mykey]", "consumerSecret" => "[mysecret]", "requestTokenUrl" => "http://api.twitter.com/oauth2/token" ); $consumer = new \ZendOAuth\Consumer($config); try { $token = $consumer->getRequestToken(); var_dump($token); } catch (\Exception $e) { echo "Error getting token: ".$e->getMessage()."<br>\n"; } This still doesn't work however; the main reason being that twitter *requires* a body that says: *grant_type=client_credentials* So, i created a few of my own classes extending on the existing ones, that allowed me to set a body. I'm using Curl as the adapter for the http-client and i don't know if it's because of that, but existing methods like setContent didn't have any effect on the body. This is what it now looks like: $adapter = new \MyOwn\Http\Client\Adapter\TwitterCurl(); $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false); $config = array( "consumerKey" => "[mykey]", "consumerSecret" => "[mysecret]", "requestTokenUrl" => "https://api.twitter.com/oauth2/token" ); $consumer = new \MyOwn\OAuth\Consumer($config); $client = $consumer->getHttpClient(); $client->setAdapter($adapter); $consumer->setHttpClient($client); try { $token = $consumer->getRequestToken(); var_dump($token); } catch (\Exception $e) { echo "Error getting token: ".$e->getMessage()."<br>\n"; } And finally, after lots of reading and debugging i got a response with a bearer-token! But, i'm still stuck, actually interfacing with twitter. When i create a zendserver/twitter object, passing in my token, it keeps saying it's not valid. I've found a hundred different examples of how to pass in the variables, with no clear idea of which one is the right one. This is, among other things, what i've tried: $twitter = new \ZendService\Twitter\Twitter(array( 'accessToken' => $token, 'oauth_options' => array( 'username' => $username, ), )); $adapter = new \Zend\Http\Client\Adapter\Curl(); $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false); $twitter->getHttpClient()->setAdapter($adapter); $response = $twitter->account->verifyCredentials(); The $token being the variable from the previous code-snippet This gains me a 400 - Bad Request though When i capture the outoing request i can see that this is sent: GET /1.1/account/verify_credentials.json HTTP/1.1 Host: api.twitter.com Connection: close Accept-Encoding: gzip, deflate User-Agent: Zend\Http\Client It doesn't communicate the token at all! I really hope there is someone here who can shed some light on things. I've been going at this for three days now, reading loads of (outdated) documenation and hacking my way around this. I starting to get the feeling it would've been far easier to build this myself from scratch :( -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/various-ZendService-Twitter-problems-due-to-recent-API-change-tp4660002.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
