Yii Framework Forum: Pogostick Extension - updateStatus - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Pogostick Extension - updateStatus Post to Twitter API Rate Topic: -----

#1 User is offline   jebarco1 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 21-September 11
  • Location:atlanta, ga

Posted 21 September 2011 - 05:37 PM

Im currently new to YII framework and my project require me to post twitter status updates via oauth. I have the oauth token working for the authorized user. I ran the verifyCredentials() function and I sucessfully return data. When I try to use the updateStatus is where I get the error below.


Error::

Error making OAuth fetch request in CPSTwitterApi: {Invalid auth/bad
request (got a 400, expected HTTP/1.1 20X or a redirect)}



Addition Question :: CPSApiComponent.php

This file has the following ($_sResults = $this->makeHttpRequest( $_sUrl, $_sQuery, 'GET', $this->userAgent );)

Should this be POST instead of GET? From the comments in the CPSTwitterApi.php the updateStatus function says " Request must be a POST."


-------------------------------------------


My code:


Yii::app()->twitter->loadData($arTwitterUser[1], $arTwitterUser[0], true, array('oauth_token' => $arTwitterOAuth[0],'oauth_token_secret' => $arTwitterOAuth[1]));
echo Yii::trace(CVarDumper::dumpAsString(Yii::app()->twitter->checkLoadData()),'vardump');

$_arResults = Yii::app()->twitter->verifyCredentials(); // Works
echo Yii::trace(CVarDumper::dumpAsString($_arResults),'vardump');

$_arResults = Yii::app()->twitter->updateStatus('This is a test of Twitter API');
echo Yii::trace(CVarDumper::dumpAsString($_arResults),'vardump'); // Doesnt
0

#2 User is offline   jptsetung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-March 10

Posted 05 March 2012 - 04:20 PM

View Postjebarco1, on 21 September 2011 - 05:37 PM, said:

Im currently new to YII framework and my project require me to post twitter status updates via oauth. I have the oauth token working for the authorized user. I ran the verifyCredentials() function and I sucessfully return data. When I try to use the updateStatus is where I get the error below.


Error::

Error making OAuth fetch request in CPSTwitterApi: {Invalid auth/bad
request (got a 400, expected HTTP/1.1 20X or a redirect)}



Addition Question :: CPSApiComponent.php

This file has the following ($_sResults = $this->makeHttpRequest( $_sUrl, $_sQuery, 'GET', $this->userAgent );)

Should this be POST instead of GET? From the comments in the CPSTwitterApi.php the updateStatus function says " Request must be a POST."


-------------------------------------------


My code:


Yii::app()->twitter->loadData($arTwitterUser[1], $arTwitterUser[0], true, array('oauth_token' => $arTwitterOAuth[0],'oauth_token_secret' => $arTwitterOAuth[1]));
echo Yii::trace(CVarDumper::dumpAsString(Yii::app()->twitter->checkLoadData()),'vardump');

$_arResults = Yii::app()->twitter->verifyCredentials(); // Works
echo Yii::trace(CVarDumper::dumpAsString($_arResults),'vardump');

$_arResults = Yii::app()->twitter->updateStatus('This is a test of Twitter API');
echo Yii::trace(CVarDumper::dumpAsString($_arResults),'vardump'); // Doesnt



I have exactly the same problem, and after looking around with google, it seems it's not an easy one to fix. Did you manage to fix it?

[edit]] I got it working with php 5.3. I had to modify the files CPSTwitterApi.php and the file CPSOAuthComponent.php to make it work. Mabe the library was designed for an older version of PHP and was not compatible with the latest version of PHP.

In CPSTWitterApi.php
//$_arOptions =& $this->getOptions();
//$_arOptions[ 'requestMap' ][ $_sLastController ][ $sAction ] = array( 'params' => $arParams, 'options' => $arOptions, 'controller' => $_sLastController );
$this->requestMap[ $_sLastController ][ $sAction ] = array( 'params' => $arParams, 'options' => $arOptions, 'controller' => $_sLastController );


In CPSOAuthComponent.php

$_arMap = ( isset( $this->requestMap[ $this->apiToUse ][ $sAction ] ) ) ? $this->requestMap[ $this->apiToUse ][ $sAction ] : null;
$_arOptions = ( isset( $_arMap[ 'options' ] ) ) ? $_arMap[ 'options' ] : null;
$_arReqOneOf = ( isset( $_arOptions[ '_requireOneOf' ] ) ) ? $_arOptions[ '_requireOneOf' ] : null;
if (isset( $_arOptions[ '_method' ] )) $_sMethod=$_arOptions[ '_method' ];
else {
    if ($sMethod!==null) {
        $_sMethod=$sMethod;
    } else {
        $_sMethod=CPSApiBehavior::HTTP_GET;
    }
}
 
$_arParams = ( isset( $_arMap[ 'params' ] ) ) ? $_arMap[ 'params' ] : null;

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users