Giter Club home page Giter Club logo

Comments (8)

nWidart avatar nWidart commented on June 10, 2024

It seems to be because of this:

if ( $response->getResponseCode() >= 400 ) {
            throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode() );
        }

I'm getting a 401 response code, I don't know why ... And the message property doesn't exist.
Why would it throw a 401 response, since the authentication before went all fine, (authorising the app to access data from pinterest user).

Also, everything worked before this new change on the api/package, so not sure what's going wrong now.

from pinterest-api-php.

nWidart avatar nWidart commented on June 10, 2024

When I var_dump the $resonse_data variable, it has: "{"error": "invalid_grant"}"

According to the docs however, it's correct.

https://developers.pinterest.com/docs/api/overview/

grant_type  Must take the value authorization_code.

from pinterest-api-php.

nWidart avatar nWidart commented on June 10, 2024

In the Request class, I dump the following:

// Execute request and catch response
$response_data = $ch->execute();
dd($ch->getErrors(), $ch->hasErrors(), $response_data);

which returns:

""
0
"{"error": "invalid_grant"}"

So it says it doesn't have any errors, but the $response_data does contain an error.

from pinterest-api-php.

dirkgroenen avatar dirkgroenen commented on June 10, 2024

Thanks for your excellent debugging! 👍

I might check this one out at the end of the day. The origin of the issue is probably related to Pinterest changing something in their API/oAuth process, but it looks like the response class/error handling of the wrapper needs some updating too.

from pinterest-api-php.

dirkgroenen avatar dirkgroenen commented on June 10, 2024

Ok I just checked some things:

I have a simple running version of the package running on my server which is working fine. The code it's using is the following:

boot.php (required in index.php and callback.php):

require "vendor/autoload.php";

use DirkGroenen\Pinterest\Pinterest;

$pinterest = new Pinterest(secret, secret);

if(isset($_GET["code"])){
    $token = $pinterest->auth->getOAuthToken($_GET["code"]);
    $pinterest->auth->setOAuthToken($token->access_token);
}

if(isset($_GET["access_token"])){
    $pinterest->auth->setOAuthToken($_GET["access_token"]);
}

index.php:

<body>
    <h1>Login with Pinterest</h1>
    <p>Use this <a href="<?php echo $pinterest->auth->getLoginUrl('https://bitlabs.nl/pinterest/callback.php', array('read_public')); ?>">link to login</a> with your Pinterest account.</p>
</body>

callback.php:

<h1>Hey you!</h1>
<pre>
    <?php var_dump($pinterest->users->me()); ?>
</pre>

Can you check your code against the above?

from pinterest-api-php.

nWidart avatar nWidart commented on June 10, 2024

I have the same setup basically, only in a framework.

I have:

  • view 1 which shows link to login
  • this redirects to back to callback method on controller
  • callback method does the $pinterest->auth->getOAuthToken($_GET["code"]); , which throws the error mentioned.

from pinterest-api-php.

nWidart avatar nWidart commented on June 10, 2024

Ok I just refreshed the page, and now for some reason I do have an access_token.

I'm not sure what happened.

Sorry for the trouble and thanks for you support! 👍

from pinterest-api-php.

dirkgroenen avatar dirkgroenen commented on June 10, 2024

Strange stuff happens. Let me know if it somehow comes back.

from pinterest-api-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.