inakiabt / etsy-php

Etsy API wrapper for PHP
74 stars 59 forks source link

Probleam in creatingListing #32

Closed Tekrajs closed 6 years ago

Tekrajs commented 6 years ago

Hello, With this sdk , I am trying to connect to etsy shop and do listing with createListing like this :

                       $auth = require(FCPATH.'/credential.php');
    $access_token = '2aa947e452b2b16e671b23b2eb9143';// get from db
    $access_token_secret ='ceb0bb4e8e'; // get from db
    $client = new Etsy\EtsyClient($auth['consumer_key'], $auth['consumer_secret']);
    $client->authorize($auth['access_token'], $auth['access_token_secret']);
    echo '<pre>'; 
    print_r($client);
    echo '</pre>';
    $this->api = new Etsy\EtsyApi($client);
    $args = array(
        'data' => array(
            "quantity" => 123456,
            "title" => "string",
            "description" => "text",
            "price" => 12.3456,
            "materials" => array('wood, plastic'),
            "shipping_template_id" => 123456,
            "shop_section_id" => 123456,
            "image_ids" => array(1), // Multimple?
            "non_taxable" => false,
            "state" => "active",
            "processing_min" => 123456,
            "processing_max" => 123456,
            "category_id" => 123456,
            "taxonomy_id" => 123456,
            "tags" => array('fashion, othertag'),
            "who_made" => "collective",
            "is_supply" => true,
            "when_made" => "2000_2009",
            "recipient" => "men",
            "occasion" => "baptism",
            "style" => array('style1, style2')
        )
    );

    $result = $this->api->createListing($args);
    echo '<pre>'; 
    print_r($result);
    echo '</pre>';
    die;

But it gives me this error:
An uncaught Exception was encountered Type: Etsy\EtsyRequestException

Message: Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect): Array ( [quantity] => 123456 [title] => string [description] => text [price] => 12.3456 [materials] => Array ( [0] => wood, plastic ) [shipping_template_id] => 123456 [shop_section_id] => 123456 [image_ids] => Array ( [0] => 1 ) [non_taxable] => 0 [state] => active [processing_min] => 123456 [processing_max] => 123456 [category_id] => 123456 [taxonomy_id] => 123456 [tags] => Array ( [0] => fashion, othertag ) [who_made] => collective [is_supply] => 1 [when_made] => 2000_2009 [recipient] => men [occasion] => baptism [style] => Array ( [0] => style1, style2 ) ) This method requires scope authentication not granted.Array ( [url] => https://openapi.etsy.com/v2/private/listings?oauth_consumer_key=zies3vygeshxe9m8seyxb3qu&oauth_signature_method=HMAC-SHA1&oauth_nonce=18621825675a745530af6442.20859604&oauth_timestamp=1517573424&oauth_version=1.0&oauth_token=2aa947e452b2b16e671b23b2eb9143&oauth_signature=A2MaZ04rQ3qRBBoAviKUJj6uSdE%3D [http_code] => 403 [content_type] => text/plain;charset=UTF-8 [download_content_length] => 54 [size_download] => 54 [size_upload] => 394 ) Array ( [sbs] => POST&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Fprivate%2Flistings&category_id%3D123456%26description%3Dtext%26image_ids%3D1%26is_supply%3D1%26materials%3Dwood%252C%2520plastic%26non_taxable%3D0%26oauth_consumer_key%3Dzies3vygeshxe9m8seyxb3qu%26oauth_nonce%3D18621825675a745530af6442.20859604%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1517573424%26oauth_token%3D2aa947e452b2b16e671b23b2eb9143%26oauth_version%3D1.0%26occasion%3Dbaptism%26price%3D12.3456%26processing_max%3D123456%26processing_min%3D123456%26quantity%3D123456%26recipient%3Dmen%26shipping_template_id%3D123456%26shop_section_id%3D123456%26state%3Dactive%26style%3Dstyle1%252C%2520style2%26tags%3Dfashion%252C%2520othertag%26taxonomy_id%3D123456%26title%3Dstring%26when_made%3D2000_2009%26who_made%3Dcollective [headers_sent] => Content-Type: application/x-www-form-urlencoded [headers_recv] => HTTP/1.1 403 Forbidden Server: Apache Set-Cookie: uaid=uaid%3Dp3fBn4LRkisO38yEhzqABvQRJ3YL%26_now%3D1517573426%26_slt%3DaXyj4cix%26_kid%3D1%26_ver%3D1%26_mac%3DSv29JtzlzexCmpGB4RNm68Elf-YiBuUNkzrKzDkDBds.; expires=Tue, 05-Mar-2019 04:28:46 GMT; Max-Age=34186700; path=/; domain=.etsy.com; secure; HttpOnly X-Etsy-Request-Uuid: EurMhPOHwFyblnxPzpAcFwIN0105 X-RateLimit-Limit: 10000 X-RateLimit-Remaining: 9998 X-Error-Detail: This method requires scope authentication not granted. Cache-Control: private Set-Cookie: zuaid=uaid%3Dp3fBn4LRkisO38yEhzqABvQRJ3YL%26_now%3D1517573426%26_slt%3DI5Y2TbCA%26_kid%3D1%26_ver%3D1%26_mac%3DzSjDq5vkougXgxnzL2Nu6F1XBzkc3JnTWZy0s4MAmf8.; expires=Sun, 04-Mar-2018 12:10:26 GMT; Max-Age=2592000; path=/; domain=.etsy.com; secure; HttpOnly Set-Cookie: user_prefs=EGk7jmwM0GlInSXFhG37Z_LQ9rRjZACCqJJQIxgdnVeak6NDMhHLAAA.; expires=Sat, 02-Feb-2019 12:10:26 GMT; Max-Age=31536000; path=/; domain=.etsy.com Content-Type: text/plain;charset=UTF-8 Content-Length: 54 Accept-Ranges: bytes Date: Fri, 02 Feb 2018 12:10:26 GMT Via: 1.1 varnish Connection: close X-Served-By: cache-ams4129-AMS X-Cache: MISS X-Cache-Hits: 0 X-Timer: S1517573426.251245,VS0,VE359 [body_sent] => quantity=123456&title=string&description=text&price=12.3456&materials=wood%2C%20plastic&shipping_template_id=123456&shop_section_id=123456&image_ids=1&non_taxable=0&state=active&processing_min=123456&processing_max=123456&category_id=123456&taxonomy_id=123456&tags=fashion%2C%20othertag&who_made=collective&is_supply=1&when_made=2000_2009&recipient=men&occasion=baptism&style=style1%2C%20style2 [body_recv] => This method requires scope authentication not granted. )

Filename: /var/www/html/etsy/vendor/inakiabt/etsy-php/src/Etsy/EtsyClient.php

Line Number: 67

Backtrace:

File: /var/www/html/etsy/vendor/inakiabt/etsy-php/src/Etsy/EtsyApi.php Line: 68 Function: request

File: /var/www/html/etsy/vendor/inakiabt/etsy-php/src/Etsy/EtsyApi.php Line: 204 Function: call_user_func_array

File: /var/www/html/etsy/application/controllers/Welcome.php Line: 77 Function: __call

File: /var/www/html/etsy/index.php Line: 315 Function: require_once

How Can I add permission in url : like $url = "https://openapi.etsy.com/v2/listings".$listing_id."?scopes=listings_w";

Or is there any way to solve this ? Please help me with this. I am in a great problem with this. Have been stucked since 1 month. Thank you.

inakiabt commented 6 years ago

I would say your request was not authenticated, did you follow the steps this and this steps?

Tekrajs commented 6 years ago

Thanks for the reply. Now I am going to explain what i did to integrate your library. 1> At first I downloaded the libarary via composer in codeigniter. 2> Then i created the credential.php file on the root directory. Folder structure seems something like this . Etsy App-> ->Application ->System ->Vendor credentials.php composer.json My credential.php file looks like this: <?php return array ( 'consumer_key' => 'XXXXXXXXXXXXXXXXX', 'consumer_secret' => 'XXXXXXX', 'token_secret' => 'XXXXXXXXX', 'token' => 'XXXXXXXXXXXXXXXXXX', 'access_token' => 'XXXXXXXXXXXXXX', 'access_token_secret' => 'XXXXXXXX', );

I was not clear with this https://github.com/inakiabt/etsy-php/blob/master/README.md#oauth-configuration-script step so I did fetched all the credential by using default php outh as suggested by etsy outh here https://www.etsy.com/developers/documentation/getting_started/oauth. Now at first when i do as follow: public function index() { $auth = require(FCPATH.'/credential.php'); $access_token = '2aa947e452b2b16e671b23b2eb9143';// get from db $access_token_secret ='ceb0bb4e8e'; // get from db $client = new Etsy\EtsyClient($auth['consumer_key'], $auth['consumer_secret']);

$client->authorize($auth['access_token'], $auth['access_token_secret']);

$api = new Etsy\EtsyApi($client); echo "

";
print_r($api->getUser(array('params' => array('user_id' => 'SELF'))));
exit;

}

it response me back with followig data

Array ( [count] => 1 [results] => Array ( [0] => Array ( [user_id] => 90604669 [login_name] => sabinthapa1 [primary_email] => contact@exportfeed.com [creation_tsz] => 1462183677 [user_pub_key] => Array ( [key] => -----BEGIN PUBLIC KEY----- PUBLIC KEY HERE -----END PUBLIC KEY-----

                        [key_id] => 45178705681
                    )

                [referred_by_user_id] =>
                [feedback_info] => Array
                    (
                        [count] => 0
                        [score] =>
                    )

                [awaiting_feedback_count] => 0
                [use_new_inventory_endpoints] => 1
            )

    )

[params] => Array
    (
        [user_id] => __SELF__
    )

[type] => User
[pagination] => Array
    (
    )

)

And When I do use that previously defined method, it is giving that error. What am i missing ? Or how to use the below part ?

OAuth configuration script

Etsy API uses OAuth 1.0 authentication, so lets setup our credentials.

The script scripts/auth-setup.php will generate an OAuth config file required by the Etsy client to make signed requests. Example:

export ETSY_CONSUMER_KEY=qwertyuiop123456dfghjexport ETSY_CONSUMER_SECRET=qwertyuiop12

php scripts/auth-setup.php /path/to/my-oauth-config-destination.php

It will show an URL you must open, sign in on Etsy and allow the application. Then copy paste the verification code on the terminal. (On Mac OSX, it will open your default browser automatically) What do you mean by this step actually? Should I need to put my credential in auth-setup.php or in credentials.php ? I woulod be really greatfull to you if you help me out of this. Thanks.

On Sat, Feb 3, 2018 at 5:42 PM, Iñaki Abete notifications@github.com wrote:

I would say your request was not authenticated, did you follow the steps this https://github.com/inakiabt/etsy-php/blob/master/README.md#oauth-configuration-script and this https://github.com/inakiabt/etsy-php/blob/master/README.md#initialization steps?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/inakiabt/etsy-php/issues/32#issuecomment-362800894, or mute the thread https://github.com/notifications/unsubscribe-auth/AXL8Fd2gRGEy1YZd1d97SDCaQ7BKzAKTks5tREm5gaJpZM4R3Ho8 .

inakiabt commented 6 years ago

You must run the auth-setup.php script to get the access and secret tokens.

Try to run like this:

export ETSY_CONSUMER_KEY=YourConsumerKey
ETSY_CONSUMER_SECRET=YourConsumerSecret

php vendor/inakiabt/etsy-php/scripts/auth-setup.php /path/to/my-oauth-config-destination.php
Tekrajs commented 6 years ago

@inakiabt Thank You so much for your response. I solved that part . Now shipping template is created and i want to upload images to etsy. As your code snipits I tried this :+1:

  $source = FCPATH.'/sources/test.jpg';
   $auth = require(FCPATH.'/credential.php');
    $access_token = '2aa947e452b2b16e671b23b2eb9143';// get from db
    $access_token_secret ='ceb0bb4e8e'; // get from db
    $client = new Etsy\EtsyClient($auth['consumer_key'], $auth['consumer_secret']);

    $client->authorize($auth['access_token'], $auth['access_token_secret']);

    $api = new Etsy\EtsyApi($client);     
  $listing_image = array(
    'params' => array(
        'listing_id' => '152326352'
    ),
    'data' => array(
        'image' => array('@'.$source.';type=image/jpeg')

)); print_r($api->uploadListingImage($listing_image));exit;

But it gives me this error message: Type: Etsy\EtsyRequestException

Message: Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect): Array ( [@image] => @/var/www/html/etsy//sources/test.jpg;type=image/jpeg ) Access denied (not owner)Array ( [http_code] => 403 [content_type] => text/plain;charset=UTF-8 [url] => https://openapi.etsy.com/v2/private/listings/152326352/images?oauth_consumer_key=zies3vygeshxe9m8seyxb3qu&oauth_signature_method=HMAC-SHA1&oauth_nonce=7591563285a79a987bfb630.35204686&oauth_timestamp=1517922695&oauth_version=1.0&oauth_token=75966c5c7711aa76b2d7eb67f47cc2&oauth_signature=ITjl3WAVC0fWq6BCTrZL10KKNHE%3D [header_size] => 1033 [request_size] => 488 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.404144 [namelookup_time] => 0.509152 [connect_time] => 0.569432 [pretransfer_time] => 0.860227 [size_upload] => 28652 [size_download] => 25 [speed_download] => 10 [speed_upload] => 11917 [download_content_length] => 25 [upload_content_length] => 28652 [starttransfer_time] => 0.860233 [redirect_time] => 0 [headers_recv] => HTTP/1.1 403 Forbidden Server: Apache X-Etsy-Request-Uuid: EumMS2ef_WDbn1xOuyRPe-bdGSd9 X-RateLimit-Limit: 10000 X-RateLimit-Remaining: 9986 X-Error-Detail: Access denied (not owner) Cache-Control: private Content-Length: 25 Content-Type: text/plain;charset=UTF-8 Date: Tue, 06 Feb 2018 13:11:38 GMT Connection: close Set-Cookie: uaid=uaid%3DoXIlWeU3CqFOXOUO86vKzLbAmKvp%26_now%3D1517922697%26_slt%3DYOBILDU6%26_kid%3D1%26_ver%3D1%26_mac%3DxIDQz302vTgVZ6tKw2N5nsQO22bcIjdr9mNduGy2GTQ.; expires=Sat, 09-Mar-2019 05:29:57 GMT; Max-Age=34186700; path=/; domain=.etsy.com; secure; HttpOnly Set-Cookie: zuaid=uaid%3DoXIlWeU3CqFOXOUO86vKzLbAmKvp%26_now%3D1517922697%26_slt%3DRAsoItIv%26_kid%3D1%26_ver%3D1%26_mac%3DJoI5NitvigRfzbXY-iiEfc0KIqu8D9hgEpSatWfJnGg.; expires=Thu, 08-Mar-2018 13:11:37 GMT; Max-Age=2592000; path=/; domain=.etsy.com; secure; HttpOnly Set-Cookie: user_prefs=WbWDklsD5p0CxA7joIMraQ-h231jZACCqMqVnTA6Oq80J0eHZCKWAQA.; expires=Wed, 06-Feb-2019 13:11:37 GMT; Max-Age=31536000; path=/; domain=.etsy.com ) Array ( [sbs] => POST&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Fprivate%2Flistings%2F152326352%2Fimages&oauth_consumer_key%3Dzies3vygeshxe9m8seyxb3qu%26oauth_nonce%3D7591563285a79a987bfb630.35204686%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1517922695%26oauth_token%3D75966c5c7711aa76b2d7eb67f47cc2%26oauth_version%3D1.0 [headers_sent] => POST /v2/private/listings/152326352/images?oauth_consumer_key=zies3vygeshxe9m8seyxb3qu&oauth_signature_method=HMAC-SHA1&oauth_nonce=7591563285a79a987bfb630.35204686&oauth_timestamp=1517922695&oauth_version=1.0&oauth_token=75966c5c7711aa76b2d7eb67f47cc2&oauth_signature=ITjl3WAVC0fWq6BCTrZL10KKNHE%3D HTTP/1.1 Host: openapi.etsy.com User-Agent: PECL-OAuth/2.0.2 Accept: / Content-Length: 28652 Content-Type: multipart/form-data; boundary=------------------------689dc7de8d6f169a [headers_recv] => HTTP/1.1 403 Forbidden Server: Apache X-Etsy-Request-Uuid: EumMS2ef_WDbn1xOuyRPe-bdGSd9 X-RateLimit-Limit: 10000 X-RateLimit-Remaining: 9986 X-Error-Detail: Access denied (not owner) Cache-Control: private Content-Length: 25 Content-Type: text/plain;charset=UTF-8 Date: Tue, 06 Feb 2018 13:11:38 GMT Connection: close Set-Cookie: uaid=uaid%3DoXIlWeU3CqFOXOUO86vKzLbAmKvp%26_now%3D1517922697%26_slt%3DYOBILDU6%26_kid%3D1%26_ver%3D1%26_mac%3DxIDQz302vTgVZ6tKw2N5nsQO22bcIjdr9mNduGy2GTQ.; expires=Sat, 09-Mar-2019 05:29:57 GMT; Max-Age=34186700; path=/; domain=.etsy.com; secure; HttpOnly Set-Cookie: zuaid=uaid%3DoXIlWeU3CqFOXOUO86vKzLbAmKvp%26_now%3D1517922697%26_slt%3DRAsoItIv%26_kid%3D1%26_ver%3D1%26_mac%3DJoI5NitvigRfzbXY-iiEfc0KIqu8D9hgEpSatWfJnGg.; expires=Thu, 08-Mar-2018 13:11:37 GMT; Max-Age=2592000; path=/; domain=.etsy.com; secure; HttpOnly Set-Cookie: user_prefs=WbWDklsD5p0CxA7joIMraQ-h231jZACCqMqVnTA6Oq80J0eHZCKWAQA.; expires=Wed, 06-Feb-2019 13:11:37 GMT; Max-Age=31536000; path=/; domain=.etsy.com [body_sent] => --------------------------689dc7de8d6f169a Content-Disposition: form-data; name="image"; filename="@/var/www/html/etsy//sources/test.jpg;type=image/jpeg" Content-Type: image/jpeg �����ut�ka����[��&V����X�jO�4���ߐѣ/]� �T,9{.�e� ҋ����p0ܛ=9z�gI�!�\a�'\C����S]���2�bkW��x �k [body_recv] => Access denied (not owner) [info] => Trying 23.207.135.114... Connected to openapi.etsy.com (23.207.135.114) port 443 (#0) found 148 certificates in /etc/ssl/certs/ca-certificates.crt found 597 certificates in /etc/ssl/certs ALPN, offering http/1.1 SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384 server certificate verification OK server certificate status verification SKIPPED common name: .etsy.com (matched) server certificate expiration date OK server certificate activation date OK certificate public key: RSA certificate version: #3 subject: CN=.etsy.com start date: Thu, 11 Aug 2016 00:00:00 GMT expire date: Sun, 11 Aug 2019 23:59:59 GMT issuer: C=US,O=GeoTrust Inc.,CN=RapidSSL SHA256 CA compression: NULL ALPN, server accepted to use http/1.1 Closing connection 0 )

Filename: /var/www/html/etsy/vendor/inakiabt/etsy-php/src/Etsy/EtsyClient.php

Line Number: 67

And line 67 is : } catch (\OAuthException $e) { throw new EtsyRequestException($e, $this->oauth, $params); } What owner thing is it talking about ? Can you please explain this ?Should i need to do something at etsy shop?

inakiabt commented 6 years ago

I'm not sure what's going on with that, being honest I'm not an expert with Etsy API, I've just created a wrapper around it 😀

Great you could solved your main issue. Closing this one.