Created
September 6, 2012 16:57
-
-
Save umbrae/3658512 to your computer and use it in GitHub Desktop.
Sample image upload for Etsy Listings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('OAUTH_CONSUMER_KEY', 'YOUR_CONSUMER_KEY_HERE'); | |
| define('OAUTH_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET_HERE'); | |
| $listing_id="ID_OF_LISTING_THAT_YOU_OWN_HERE"; | |
| $filename="FILENAME_THAT_EXISTS_ON_THE_FILESYSTEM_HERE.JPG"; | |
| $mimetype="image/jpeg"; | |
| $access_token="ACCESS_TOKEN_YOU_HAVE_AUTHENTICATED_WITH_HERE"; | |
| $access_token_secret="ACCESS_SECRET_THAT_YOU_HAVE_AUTHENTICATED_WITH_HERE"; | |
| // You must define the constants OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET | |
| // You must also assign values to the variables $access_token, $access_token_secret, | |
| // $listing_id and $filename, and $mimetype. | |
| // Your image file is assumed to be in the same directory as this code. | |
| $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET); | |
| $oauth->enableDebug(); | |
| $oauth->setToken($access_token, $access_token_secret); | |
| try { | |
| $source_file = dirname(realpath(__FILE__)) ."/$filename"; | |
| $url = "http://openapi.etsy.com/v2/listings/".$listing_id."/images"; | |
| $params = array('@image' => '@'.$source_file.';type='.$mimetype); | |
| $oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST); | |
| $json = $oauth->getLastResponse(); | |
| print_r(json_decode($json, true)); | |
| } catch (OAuthException $e) { | |
| // You may want to recover gracefully here... | |
| print $oauth->getLastResponse()."\n"; | |
| print_r($oauth->debugInfo); | |
| die($e->getMessage()); | |
| } |
Error as well: Image file or image_id string must be included
Error as well: Image file or image_id string must be included
Image file or image_id string must be included
when send content of image file get following response
[body_sent] => %40image=84090%3Btype%3Dimage%2Fpng
[body_recv] => The request body is too large
This is the example from Etsy's documentation, which doesn't actually work. You can get it working using oauth and curl: https://notestoself.dev/posts/etsy-api-php-oauth-listing-image-upload/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: Image file or image_id string must be included