Happyr / LinkedIn-API-client

A library to connect with LinkedIn API. Perfect if you are looking for an API client or SDK for LinkedIn
MIT License
198 stars 97 forks source link

Error With Guzzle #133

Open stephenvicino opened 7 years ago

stephenvicino commented 7 years ago
Q A
Bug? Yes
New Feature? no
Are you using composer? yes
Version 1

Actual Behavior

Fatal error: Call to undefined method GuzzleHttp\Client::sendAsync()

Expected Behavior

Oauth

Steps to Reproduce

 $linkedIn->setHttpClient(new \Http\Adapter\Guzzle6\Client());
  $linkedIn->setHttpMessageFactory(new Http\Message\MessageFactory\GuzzleMessageFactory());

When I click the login URL, I get the error: Fatal error: Call to undefined method GuzzleHttp\Client::sendAsync()

Nyholm commented 7 years ago

Interesting.

I've tried to reproduce this but failed. What does your composer.json look like? Can you provide a stack trace? Who is trying to call GuzzleHttp\Client::sendAsync()?

stephenvicino commented 7 years ago

Full Error Message:

Fatal error: Call to undefined method GuzzleHttp\Client::sendAsync() in /var/www/includes/vendor/php-http/guzzle6-adapter/src/Client.php on line 64

My Composer.json: "league/csv": "~7.1", "aws/aws-sdk-php": "^3.0", "mandrill/mandrill": "1.0.", "mixpanel/mixpanel-php" : "2.", "stripe/stripe-php": "3.", "abraham/twitteroauth": "^0.6.2", "pusher/pusher-php-server": "^2.2", "smalot/pdfparser": "^0.9.25", "eventviva/php-image-resize": "1.5.", "hashids/hashids": "^1.0", "spatie/pdf-to-image": "^1.1", "nojimage/twitter-text-php": "^1.1", "twilio/sdk": "^4.10", "lusitanian/oauth": "^0.8.9", "thomaswelton/gravatarlib": "^0.1.0", "vinelab/rss": "^1.0", "php-ffmpeg/php-ffmpeg": "^0.6.1", "php-http/curl-client": "^1.6", "guzzlehttp/psr7": "^1.3", "php-http/message": "^1.4", "happyr/linkedin-api-client": "^1.0", "php-http/guzzle6-adapter": "^1.1"

This is the call that is failing: $user=$linkedIn->get('v1/people/~:(firstName,lastName)');

It generates the getLoginUrl() fine.

Nyholm commented 7 years ago

That is very strange. It looks alright, I tried to reproduce but I still cant..

Can you show me the output of:

composer show -i

(If you want to be more private it may be okey by:)

composer show -i | grep guzzle  
stephenvicino commented 7 years ago

You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages. guzzlehttp/guzzle 6.2.2 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.3.0 Guzzle promises library guzzlehttp/psr7 1.3.1 PSR-7 message implementation php-http/guzzle6-adapter v1.1.1 Guzzle 6 HTTP Adapter

Nyholm commented 7 years ago

It looks like you got all the proper versions and everything is fine.. Do you use the composer autoloader?

Do you have the same issues when you use the curl client?

stephenvicino commented 7 years ago

I am unsure if this is related, but somehow I am getting a new error message:

Catchable fatal error: Method Happyr\LinkedIn\AccessToken::__toString() must return a string value in /vendor/happyr/linkedin-api-client/src/LinkedIn.php on line 111

I tracked it down to this I believe: [__PHP_Incomplete_Class_Name] => Happyr\LinkedIn\AccessToken

Nyholm commented 7 years ago

That is unrelated. But also strange.

What PHP version do you run?

stephenvicino commented 7 years ago

PHP Version 5.5.9-1ubuntu4.20

Ok, I got past the Guzzle error by just removing everything but your project and dependencies. I will try to narrow it down to see what package is causing it, however I am stuck on the other error now.

stephenvicino commented 7 years ago

Ok, this combination works: "guzzlehttp/guzzle": "^6.2", "php-http/curl-client": "^1.6", "guzzlehttp/psr7": "^1.3", "php-http/message": "^1.4", "happyr/linkedin-api-client": "^1.0"

Nyholm commented 7 years ago

That's what you had before, right? https://github.com/Happyr/LinkedIn-API-client/issues/133#issuecomment-265195092

stephenvicino commented 7 years ago

Minus the php-http/guzzle6-adapter v1.1.1 Guzzle 6 HTTP Adapter

Nyholm commented 7 years ago

Okey, so now you are using the Curl client, right?

stephenvicino commented 7 years ago

Yes, not setting the http client

stephenvicino commented 7 years ago

I reinstalled the guzzle6 adapter and am using Guzzle now,

However I can't get past the

Method Happyr\LinkedIn\AccessToken::__toString() must return a string value

error now.

Nyholm commented 7 years ago

Can you debug this line: https://github.com/Happyr/LinkedIn-API-client/blob/master/src/AccessToken.php#L42

And tell me what $this->token is before we print it?

stephenvicino commented 7 years ago

Sure thing;

$this->token has the following value PHP_Incomplete_Class Object ( [PHP_Incomplete_Class_Name] => Happyr\LinkedIn\AccessToken [token:Happyr\LinkedIn\AccessToken:private] => I REMOVED THE ACCESS TOKEN [expiresAt:Happyr\LinkedIn\AccessToken:private] => DateTime Object ( [date] => 2017-02-04 10:48:59 [timezone_type] => 3 [timezone] => America/New_York )

)

Nyholm commented 7 years ago

Can you try this branch to see if I fixed your problems: https://github.com/Happyr/LinkedIn-API-client/tree/issue-133

(You may have to clear your browser cookies)

composer require happyr/linkedin-api-client:dev-issue-133
stephenvicino commented 7 years ago

It worked on first load, then I refreshed the page and got the same error message bout toString

Nyholm commented 7 years ago

Thank you for helping me debug this. I've never been able to reproduce this issue. I've push another change to that branch. Would you mind giving it another try?

stephenvicino commented 7 years ago

Still getting the error after call back,

Whats the correct way to get the access token after authenticating LinkedIn?

Nyholm commented 7 years ago

That is strange... Can you debug how that value comes in to $this->token in the first place?

stephenvicino commented 7 years ago

So it works the first time, but its gets stored in the session as an incomplete Object.

Nyholm commented 7 years ago

Okey, I've pushed a change now where I serialize the access token before we store it