zendframework / ZendOAuth

BSD 3-Clause "New" or "Revised" License
19 stars 22 forks source link

Can't send requests with the access token. #21

Open Gisleburt opened 10 years ago

Gisleburt commented 10 years ago

This might be a documentation issue, but you don't seem to be able to send requests using the access token.

From http://framework.zend.com/manual/2.0/en/modules/zendoauth.introduction.html

$config = array(
    'callbackUrl' => 'http://example.com/callback.php',
    'siteUrl' => 'http://twitter.com/oauth',
    'consumerKey' => 'gg3DsFTW9OU9eWPnbuPzQ',
    'consumerSecret' => 'tFB0fyWLSMf74lkEu9FTyoHXcazOWpbrAjTCCK48A'
);

$client = $token->getHttpClient($configuration);
$client->setUri('http://twitter.com/statuses/update.json');
$client->setMethod(Zend\Http\Client::POST);
$client->setParameterPost('status', $statusMessage);
$response = $client->request();

(It's also worth noting the difference between $config and $configuration)

However \Zend\Http\Client which is returned by ZendOAuth\OAuth::getHttpClient does not have a method called request().

I've also tried send() but this throws the error

Call to a member function connect() on a non-object in /www/vhosts/oauthexample/vendor/zendframework/zend-http/Zend/Http/Client.php on line 1358
machek commented 10 years ago

I am having same problem, it looks like same issue as https://github.com/zendframework/zf2/issues/5478 after 5 months still open?

Gisleburt commented 10 years ago

Yup, it's piss poor.

Ocramius commented 10 years ago

Yup, it's piss poor.

Awesome, did you just volunteer for writing a test/fix, @Gisleburt? :)

Gisleburt commented 10 years ago

Haha, sorry, GitHub apparently doesn't like to mention that you're email replys will be put here, I didn't even notice it was from GitHub.

My poorly worded point stands though, this module doesn't work, the documentation is crazy wrong and it hasn't been fixed, or even looked at in 3 months. I did already fix one bug but this is beyond me. My solution: I stopped using ZF2.

Ocramius commented 10 years ago

@Gisleburt that's perfectly fine, just keep an eye at where you're replying :)

ezimuel commented 10 years ago

@Gisleburt the right method to call for Zend\Http\Client is send(), not request(), the documentation is outdated. Even with that, there's a problem due to zendframework/zf2#5478. I'm going to take care of that issue in the following days. I'm sorry for the inconvenient and for the long delay on that.

machek commented 10 years ago

I don't think it's just documentation issue, try example from http://framework.zend.com/manual/2.2/en/modules/zendservice.twitter.html it fails because adapter is not set.

weierophinney commented 10 years ago

@machek Enrico specifically said as much:

the documentation is outdated. Even with that, there's a problem due to zendframework/zf2#5478.

ezimuel commented 10 years ago

@Gisleburt, @machek I was unable to reproduce the issue, I tried this example and it works fine. Can you check this code on your side? I suggest to execute a composer.phar update before. As you can see in the example, I used the send() method, I used the array() structure for the POST params in setParameterPost(), and I used the sslcapath options for HTTPS (used by Twitter).

machek commented 10 years ago

@ezimuel Here is simple test calling Twitter API - https://gist.github.com/machek/11385838 I have to specify in composer: "zendframework/zend-http": "2.2.3", then it works.

When code uses latest version 2.3.0 it dies on: PHP Fatal error: Call to a member function connect() on a non-object in \vendor\zendframework\zend-http\Zend\Http\Client.php on line 1358

I can't help myself but it look like a bug, if there is required extra step, I would say it should throw an Exception, not die.

Thanks

ezimuel commented 10 years ago

@machek The test code that you provided is for ZendService_Twitter, here we are discussing about ZendOAuth. Your issue seems to be related with zendframework/ZendService_Twitter#21. I will use this example to fix the Twitter component. I'll leave this issue opened for a while, until someone will send me a test code to reproduce the problem for ZendOAuth.

internalsystemerror commented 10 years ago

The best solution to all this that I've found so far, is to comment out lines 76-79 in ZendOAuth\Client. The base class method getAdapter() is being overriden, for what purpose I can't tell. If you want to accept this solution, I can submit a pull-request?

xyfantis commented 9 years ago

what i did to fix this is on ZendOAuth\Client getAdapter function i used parent::getAdapter() the Http\Client.php getAdapter function has a check if the adapter is set, so i think the same should apply on the ZendOAuth\Client.

titomiguelcosta commented 9 years ago

@xyfantis you are absolutely right, calling the parent method solves the problem, but since it is in the vendor folder, not a solution. Looking at the repository, the fix is only on master, no stable release for a few months, I wonder why, but after adding "zendframework/zendoauth": "dev-master" to composer and updating, problem solved.

@ezimuel you are not able to reproduce the problem cos in the example we are explicitly calling the setAdapter method, but with the example on the documentation, only using the config array passed to the ZendService\Twitter\Twitter($options), that does not happen, so we end up having the error. On master, the getAdapter was removed and we use the parent one, that checks first if it is set, if not, grab from the configuration.

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-oauth; a new issue has been opened at https://github.com/laminas/laminas-oauth/issues/6.