Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtaining an Access Token #59

Closed
nickian opened this issue Aug 29, 2016 · 2 comments
Closed

Obtaining an Access Token #59

nickian opened this issue Aug 29, 2016 · 2 comments

Comments

@nickian
Copy link

nickian commented Aug 29, 2016

Am I missing something here? I used the example code in the readme file, but I'm never redirected to the app. I just get this error:

Fatal error: Call to undefined method Mautic\Auth\ApiAuth::validateAccessToken()

That's with this code:

<?php

// Bootup the Composer autoloader
include __DIR__ . '/vendor/autoload.php';

use Mautic\Auth\ApiAuth;

$publicKey = '24gnw4fpxu3o8s4ws8ccsccwoso48ccw44s0c84s0owgscgk0w';
$secretKey = 'ky7juiwu3hcgks8coco0kcs8ocsss8o4oo40gokccw04cks0g';
$callback  = 'http://local.dev';

// ApiAuth::initiate will accept an array of OAuth settings
$settings = array(
    'baseUrl'          => 'https://mymauticinstallation.com',     
    'version'          => 'OAuth1a', 
    'clientKey'        => $publicKey,       
    'clientSecret'     => $secretKey,     
    'callback'         => $callback     
);


$auth = new ApiAuth();
$auth->newAuth($settings);

try {
    if ($auth->validateAccessToken()) {

        if ($auth->accessTokenUpdated()) {
            $accessTokenData = $auth->getAccessTokenData();
            echo $accessTokenData;
        }
    }
} catch (Exception $e) {
    // Do Error handling
}

If I just remove the try/catch, I end up with a blank page.

Thanks

@nickian
Copy link
Author

nickian commented Aug 29, 2016

Sorry, it looks like this was addressed in this thread: #58

After I updated this line:

$auth->newAuth($settings);

to this:

$auth = $auth->newAuth($settings);

It worked.

However, it should be noted that if you don't add session_start(); toward the top of the file, you'll get other "undefined variable" errors. That should be in the example code.

@escopecz
Copy link
Sponsor Member

Please check #60 if it can be like that.

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

No branches or pull requests

2 participants