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

AccessToken always NULL #14

Open
dingman opened this issue Mar 7, 2018 · 2 comments
Open

AccessToken always NULL #14

dingman opened this issue Mar 7, 2018 · 2 comments

Comments

@dingman
Copy link

dingman commented Mar 7, 2018

Hi Andrew! Thank you again for such a great library, you saved me literally hundreds of hours of dev work.

I'm integrating the library into my Laravel application and running into an issue where the AccessToken doesn't seem to be getting saved.

    public function __construct()
    {
        parent::__construct(new \GuzzleHttp\Client(), Vendor::find(5));
        define('DEBUG', true);

        $this->client->requestsPerMinute = 10;
        $this->client->clientId        = config('services.linkshareapi.client_id');
        $this->client->clientSecret    = config('services.linkshareapi.client_secret');
        $this->client->username        = config('services.linkshareapi.username');
        $this->client->password        = config('services.linkshareapi.password');
        $this->client->scope           = config('services.linkshareapi.scope');
        // Set the Token
        $this->client->accessTokenPath = storage_path('linkshare_token');
        // Get the Token
        $this->client->accessToken = $this->loadAccessToken($this->client->accessTokenPath);

    }

Is how I have it integrated.

When I dd($this->client->accessTokenPath) I get "/home/vagrant/code/storage/linkshare_token"

When I dd($this->client->accessToken) I get NULL

I would think I need to fix this to ensure the token is getting saved properly so it can be re-used instead of getting a new token on every call.

The call gets made successfully and I do see results from the call.

TIA!

@ikari7789
Copy link
Contributor

Ah, the example code is just one way of keeping track of the access token. In your own application you may want to consider storing it in a database vs a file, but that is up to you.

The way this example code works is you supply where to save the access token, which becomes a serialized AccessToken object. If the contents of the file are null, then a new access token is requested in the makeRequest method of the example.

The reason it’s returning null is because it is. Until you make a request, which requests a new access token if null, the file itself will most likely be empty.

@dingman
Copy link
Author

dingman commented Mar 8, 2018

Hi @ikari7789 thanks for the response.

In the example, my understanding is that it stores the token for X minutes so it can be re-used, then re-issues it once it needs to. What I'm seeing though in the example code, which I'm attempting to mimic, is that the token isn't getting stored at all, so each time it's issuing a new one. Am I understanding the implementation correctly? Maybe I'm storing it incorrectly in my code? I appreciate your help

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

No branches or pull requests

2 participants