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

setToken problems using own account credentials #56

Closed
ajl199 opened this issue Jan 5, 2019 · 2 comments
Closed

setToken problems using own account credentials #56

ajl199 opened this issue Jan 5, 2019 · 2 comments
Labels

Comments

@ajl199
Copy link

ajl199 commented Jan 5, 2019

I've been dropped in a little at the deep end here, and am new to just about everything involved except for PHP, so please excuse me if I'm being daft. I'm trying to authenticate against my own account, I have no need to do so for other users' accounts, so am attempting to use setToken with the oauth token and secret provided under SmugMug's web interface (Settings -> Privacy -> Authorized Services -> Token) rather than going through the token request process. Is there some reason that should't work?

My code is extremely simple and initially looked like this:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// This file is generated by Composer
require_once 'vendor/autoload.php';

// Optional, but definitely nice to have, options
$options = [
        'AppName' => 'My Test/1.0 (https://www.example.org)',
        ];
$client = new phpSmug\Client('MY API KEY', $options);
print "<br><b>Setting Token:</b><br>";
$client->setToken('MY OAUTH TOKEN', 'MY OAUTH SECRET');
# THIS IS THE POINT WHERE IT BREAKS TO START WITH
print "<br><b>Getting list of repositories:</b><br>";
$repositories = $client->get('user/MYUSERNAME!albums');
# THIS IS THE POINT WHERE IT BREAKS WITH SECRET IN OPTIONS
print_r($repositories);
...

That fails at the first point shown by my comments above, and gives me a:
"Fatal error: Uncaught exception 'phpSmug\Exception\InvalidArgumentException' with message 'An OAuthSecret is required for all SmugMug OAuth interactions.' in /var/www/other/smug/vendor/lildude/phpsmug/lib/phpSmug/Client.php:389 Stack trace: #0 /var/www/other/smug/index.php(19): phpSmug\Client->setToken('MY OAUTH TOKEN...', 'MY OAUTH SECRET...') #1 {main} thrown in /var/www/other/smug/vendor/lildude/phpsmug/lib/phpSmug/Client.php on line 389"

If I add 'OAuthSecret' => 'MY OAUTH SECRET' to options, the client seems to be instantiated OK, but it breaks at the second point shown by my comments, with::
"Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: GET https://api.smugmug.com/api/v2/user/MYUSERNAME!albums resulted in a 401 Unauthorized response: {"Code":401,"Message":"oauth_problem=signature_invalid&debug_sbs=GET&https%3A%2F%2Fapi.smugmug.com%2Fapi%2Fv2%2Fuser%2Fi (truncated...) ' in /var/www/other/smug/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/other/smug/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /var/www/other/smug/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /var/www/other/smug/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 /var/www/other/smug/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleH in /var/www/other/smug/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113"

I've tried to follow the phpsmug and smugmug API documentation with a dollop of common sense, but have clearly gone astray. Any help or hints would be appreciated.

Thanks,

Adrian

@ajl199
Copy link
Author

ajl199 commented Jan 5, 2019

Ignore me, looks like I should have been using the API secret not the oauth one as the value of OAuthSecret in $options.

I'll leave this here in case anyone else runs into the same misunderstanding.

@stale
Copy link

stale bot commented Jan 26, 2019

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed in 2 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 26, 2019
@stale stale bot closed this as completed Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant