|
![Picture of Andrew Leonard Picture of Andrew Leonard](/graphics/unknown.gif) Andrew Leonard - 2014-09-24 21:12:58
Firstly, thanks for this class - it is perfect as I am on a shared server and can't use the examples suggested by Etsy.
I have managed to get the "Log In As Etsy" example working.
However, I have now hit a bit of a brick wall.
I am trying to use the Etsy OAuth as follows:
To update the status of a listing from "draft" to "live" using a cron job that will read a database of listing ids and then activate them from "draft" to "live".
I have read through all of the documentation both here and on Etsy's developer section.
My understanding is that I need to do the following after I have created the database table.
1 - Take the example file mysqli_login_with_google.php and replace the following code (and change the $client->server to Etsy) :
if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Please go to Google APIs console page '.
'http://code.google.com/apis/console in the API access tab, '.
'create a new client ID, and in the line '.$application_line.
' set the client_id to Client ID and client_secret with Client Secret. '.
'The callback URL must be '.$client->redirect_uri.' but make sure '.
'the domain is valid and can be resolved by a public DNS.');
/* API permissions
*/
$client->scope = 'https://www.googleapis.com/auth/userinfo.email '.
'https://www.googleapis.com/auth/userinfo.profile';
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->authorization_error))
{
$client->error = $client->authorization_error;
$success = false;
}
elseif(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://www.googleapis.com/oauth2/v1/userinfo',
'GET', array(), array('FailOnAccessError'=>true), $user);
/*
* Once you were able to access the user account using the API
* you should associate the current OAuth access token a specific
* user, so you can call the API without the user presence, just
* specifying the user id in your database.
*
* In this example the user id is 1 . Your application should
* determine the right user is to associate.
*/
if($success)
$success = $client->SetUser(1);
}
}
$success = $client->Finalize($success);
}
with that from the Etsy login script:
if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Please go to Google APIs console page '.
'http://code.google.com/apis/console in the API access tab, '.
'create a new client ID, and in the line '.$application_line.
' set the client_id to Client ID and client_secret with Client Secret. '.
'The callback URL must be '.$client->redirect_uri.' but make sure '.
'the domain is valid and can be resolved by a public DNS.');
/* API permissions
*/
$client->scope = 'https://www.googleapis.com/auth/userinfo.email '.
'https://www.googleapis.com/auth/userinfo.profile';
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->authorization_error))
{
$client->error = $client->authorization_error;
$success = false;
}
elseif(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://www.googleapis.com/oauth2/v1/userinfo',
'GET', array(), array('FailOnAccessError'=>true), $user);
/*
* Once you were able to access the user account using the API
* you should associate the current OAuth access token a specific
* user, so you can call the API without the user presence, just
* specifying the user id in your database.
*
* In this example the user id is 1 . Your application should
* determine the right user is to associate.
*/
if($success)
$success = $client->SetUser(1);
}
}
$success = $client->Finalize($success);
}
2 - Once I get the above working the relevant oauth information will be stored in the database.
3 - Then I will need to write a script that will be triggered by the cron job to send to Etsy api to update the status of the scripts.
Which parts of the data stored in the database need to be sent and how do I send that to Etsy?
Am I correct in the above - if not what have I misunderstood.
Thanking you in advance.
Andrew
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2014-09-24 22:40:26 - In reply to message 1 from Andrew Leonard
Using the database classes is just meant to restore access tokens when you access the API without the user being present.
It could also refresh expired tokens and store them in the database.
In case of Etsy, it does not issue refresh tokens. So if you just store the values of the variables access_token and access_token_secret somewhere you can retrieve and restore those variables, that will be sufficient.
![Picture of Andrew Leonard Picture of Andrew Leonard](/graphics/unknown.gif) Andrew Leonard - 2014-09-25 07:45:46 - In reply to message 2 from Manuel Lemos
Hi Manuel,
Thank you for the reply - that makes it a lot easier.
When I need to call the Etsy API how do I call it using the access_token and access_token_secret?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2014-09-25 09:17:19 - In reply to message 3 from Andrew Leonard
Yes, just set those variables and that will be enough while the token remains valid.
![Picture of Andrew Leonard Picture of Andrew Leonard](/graphics/unknown.gif) Andrew Leonard - 2014-09-25 15:28:55 - In reply to message 4 from Manuel Lemos
Hi,
Apologies, I am a bit confused on how to call the etsy api now.
I can do it without the OAuth.
$apiurl1 = "https://openapi.etsy.com/v2/users/". $user_id."/profile?method=GET&api_key=" . $apikey;
$response = json_decode(file_get_contents($apiurl1));
How do I do it using these oauth paramiters?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2014-09-26 05:29:30 - In reply to message 5 from Andrew Leonard
You just need to call it as in the example with an URL like this:
'https://openapi.etsy.com/v2/users/'.$user_id.'/profile'
![Picture of Tom Picture of Tom](/graphics/unknown.gif) Tom - 2014-11-13 14:28:33 - In reply to message 6 from Manuel Lemos
Hi Manuel,
Thank you very much for this awesome libabry!
I successfuly managed to connect to Etsy using your library and can see my basic shop info like your example.
Now I want to show my shops transactions using
openapi.etsy.com/v2/private/shops/_ ...
and I changed the scope to transactions_r, but I still get this error message:
Error: it was not possible to access the API call: it was returned an unexpected response status 403 Response: This method requires scope authentication not granted.
Is this connected to the oauth token? How do I grant myself access?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2014-11-13 18:33:42 - In reply to message 7 from Tom
You are probably using a token obtained before you changed the scope.
You need to start over with a new token. You may force forgetting about the old token calling ResetAccessToken.
![Picture of Tom Picture of Tom](/graphics/unknown.gif) Tom - 2014-11-18 13:30:09 - In reply to message 8 from Manuel Lemos
Hi Manuel, thank you very very much for your fast reply! It did the trick and I can now successfuly interact with etsy.
Now I ran into the next problem, setting the access_token and access_token_secret variables to access etsy without me being present.
I read through your instructions and though they are quite in detail, I just can not get my head around where to set them. I tried it inside the CallAPI function with
$this->access_token = 'mytoken';
$this->access_token_secret = 'mysecret';
and I tried it in the login_with_etsy.php file before doing the api call with:
$client->access_token = 'mytoken';
$client->access_token_secret = 'mysecret';
and pretty much everywhere else just setting them.
Nothing seems to be working for me. Where do I need to set those variables?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2014-11-18 20:31:10 - In reply to message 9 from Tom
I am not sure what you are putting in the access_token and access_token_secret. Just make sure it is what the server returned when you authorized with a user present, and not for instance the client_id and client_secret.
If you are doing that, try setting the debug variable to true and enable your PHP error log in PHP ini. Then copy the debug output so I can see what is going on.
|