コード例 #1
0
function ebay_upload_picture($name, $blob)
{
    global $service, $token;
    $request = new Types\UploadSiteHostedPicturesRequestType();
    $request->RequesterCredentials = new Types\CustomSecurityHeaderType();
    $request->RequesterCredentials->eBayAuthToken = $token;
    $request->PictureName = $name;
    file_put_contents('d:/photo/test.jpg', $blob);
    $request->attachment(file_get_contents('d:/photo/test.jpg'), 'image/jpeg');
    $response = $service->uploadSiteHostedPictures($request);
    if ($response->Ack !== 'Failure') {
        return $response->SiteHostedPictureDetails->FullURL;
    }
    if (isset($response->Errors)) {
        print "<pre>";
        foreach ($response->Errors as $error) {
            printf("%s: %s\n%s\n\n", $error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning', $error->ShortMessage, $error->LongMessage);
        }
        die("Error uploading pictures.");
    }
}
use DTS\eBaySDK\Trading\Types;
use DTS\eBaySDK\Trading\Enums;
/**
 * Create the service object.
 *
 * For more information about creating a service object, see:
 * http://devbay.net/sdk/guides/getting-started/#service-object
 */
$service = new Services\TradingService(array('apiVersion' => $config['tradingApiVersion'], 'sandbox' => true, 'siteId' => Constants\SiteIds::US));
/**
 * Create the request object.
 *
 * For more information about creating a request object, see:
 * http://devbay.net/sdk/guides/getting-started/#request-object
 */
$request = new Types\UploadSiteHostedPicturesRequestType();
/**
 * An user token is required when using the Trading service.
 *
 * For more information about getting your user tokens, see:
 * http://devbay.net/sdk/guides/application-keys/
 */
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $config['sandbox']['userToken'];
/**
 * Give the picture a name.
 */
$request->PictureName = 'Example';
/**
 * Attach the picture that we want to upload.
 * Specifying the mime type is optional. Defaults to application/octet-stream if none is provided.