Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

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

Open
Gisleburt opened this issue Jan 21, 2014 · 15 comments
Open

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

Gisleburt opened this issue Jan 21, 2014 · 15 comments
Assignees

Comments

@Gisleburt
Copy link
Contributor

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
Copy link

machek commented Apr 22, 2014

I am having same problem, it looks like same issue as zendframework/zendframework#5478
after 5 months still open?

@Gisleburt
Copy link
Contributor Author

Yup, it's piss poor.

@Ocramius
Copy link
Member

Yup, it's piss poor.

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

@Gisleburt
Copy link
Contributor Author

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
Copy link
Member

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

@ezimuel
Copy link
Contributor

ezimuel commented Apr 24, 2014

@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/zendframework#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.

@ezimuel ezimuel self-assigned this Apr 24, 2014
@machek
Copy link

machek commented Apr 24, 2014

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
Copy link
Member

@machek Enrico specifically said as much:

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

@ezimuel
Copy link
Contributor

ezimuel commented Apr 28, 2014

@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
Copy link

machek commented Apr 28, 2014

@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
Copy link
Contributor

ezimuel commented Apr 29, 2014

@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
Copy link

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
Copy link

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
Copy link

@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
Copy link
Member

This repository has been closed and moved to laminas/laminas-oauth; a new issue has been opened at laminas/laminas-oauth#6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants