Il componente Zend_Service_Twitter è ancora per Twitters API v1.0 che verrà ritirato al 5 marzo 2013. Quindi volevo rendere pronto il mio nuovo sito web con l'interazione API di Twitter v1.1. Tutto funziona bene con v1.0, ma se cambio l'URL /1/
-/1.1/
non riesce con il codice HTTP 400 e il messaggio di errore JSON: Bad Authentication data
(Codice: 215)Zend_Service_Twitter - Prepara API v1.1
per ottenere la richiesta e token di accesso alloggiato lo stesso e funziona già, senza alcuna modifica, ma se voglio verificare le credenziali come questo ottengo l'errore che ho descritto sopra:
// Take a look for the code here: http://framework.zend.com/manual/1.12/en/zend.oauth.introduction.html
$accessToken = $twitterAuth->getAccessToken($_GET, unserialize($_SESSION['TWITTER_REQUEST_TOKEN']));
// I have a valid access token and now the problematic part
$twitter = new Zend_Service_Twitter(array(
'username' => $accessToken->getParam('screen_name'),
'accessToken' => $accessToken
));
print_r($twitter->account->verifyCredentials());
ho cambiato il codice di VerifyCredentials in Zend/Service/Twitter.php
da quello a che:
public function accountVerifyCredentials()
{
$this->_init();
$response = $this->_get('/1/account/verify_credentials.xml');
return new Zend_Rest_Client_Result($response->getBody());
}
// to
public function accountVerifyCredentials()
{
$this->_init();
$response = $this->_get('/1.1/account/verify_credentials.json');
return Zend_Json::decode($response->getBody());
}
Ora ho aggiunto prima della return Zend_Json[...]
questa linea:
print_r($this->_localHttpClient->getLastRequest());
// And I get this output of it:
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
Accept-Charset: ISO-8859-1,utf-8
Authorization: OAuth realm="",oauth_consumer_key="",oauth_nonce="91b6160db351060cdf4c774c78e2d0f2",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1349107209",oauth_version="1.0",oauth_token="hereismytoken",oauth_signature="hereisavalidsignature"
come si poteva vedere il oauth_consumer_key
(e realm
troppo) è vuoto. Potrebbe essere l'errore? Come posso risolvere questo errore (a causa della nuova versione dell'API più rigida?)? Sarebbe bello impostare in qualche modo lo oauth_consumer_key
? Se sì, come potrei gestirlo?
Edit: Ho anche trovato già un bug report sulla questione inseguitore della Zend Framework: http://framework.zend.com/issues/browse/ZF-12409 (? Magari fare un upvote)
Questo non è un nome di classe molto descrittivo. E non dovrebbe essere in uno spazio dei nomi diverso se Zend non lo scrivesse? Mi rendo conto che si tratta di modifiche, ma è buona norma utilizzare uno spazio dei nomi diverso se si sostituisce una classe. – voidstate
È solo un esempio. – yAnTar