Smugmug使用PHP上传图像API v2&;卷曲
我正在尝试使用upload API v2将图像上传到Smugmug。 我已经试了很长时间了,但没用。 这就是我到目前为止想到的 当我运行脚本时,响应如下所示:Smugmug使用PHP上传图像API v2&;卷曲,php,curl,upload,Php,Curl,Upload,我正在尝试使用upload API v2将图像上传到Smugmug。 我已经试了很长时间了,但没用。 这就是我到目前为止想到的 当我运行脚本时,响应如下所示: HTTP/1.1 100 Continue HTTP/1.1 200 OK Cache-Control: private, no-store, no-cache, max-age=1, must-revalidate Content-Type: text/xml; charset=utf-8 Date: Tue, 07 Jul 2015
HTTP/1.1 100 Continue HTTP/1.1 200 OK Cache-Control: private, no-store, no-cache, max-age=1, must-revalidate Content-Type: text/xml; charset=utf-8 Date: Tue, 07 Jul 2015 14:18:50 GMT Edge-Control: no-store Expires: Tue, 07 Jul 2015 14:18:50 GMT Server: nginx X-Powered-By: SmugMug/1.0 X-SmugMug-Hiring: How to love what you do: http://www.smugmug.com/jobs/ X-SmugMug-Values: 1/4 - Thrill your customers Content-Length: 38 Connection: keep-alive
但是文件没有上传。。
你看到代码有什么问题吗
include_once("oauth/OAuth.php");
include_once("constants.php");
$access_token = '***';
$access_token_secret = '***';
$consumer = new OAuthConsumer(API_KEY, API_KEY_SECRET);
$signature_method = new OAuthSignatureMethod_PLAINTEXT;
$token = new OAuthToken($access_token, $access_token_secret);
$req_token = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", 'http://upload.smugmug.com');
$req_token->sign_request($signature_method, $consumer, $token);
$parameters = $req_token->get_parameters();
$path = 'image.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
finfo_close($finfo);
$header[] = 'Authorization: OAuth realm="http://upload.smugmug.com/",
oauth_consumer_key='.$parameters['oauth_consumer_key'].',
oauth_token='.$parameters['oauth_token'].',
oauth_signature_method='.$parameters['oauth_signature_method'].',
oauth_signature='.$parameters['oauth_signature'].',
oauth_timestamp='.time().',
oauth_nonce='.md5(time() . mt_rand()).',
oauth_version=1.0';
$body[] = 'Accept: application/json';
$body[] = 'X-Smug-Version: v2';
$body[] = 'X-Smug-ResponseType: JSON';
$body[] = 'X-Smug-AlbumUri: /api/v2/album/******';
$body[] = 'X-Smug-Filename: image.png';
$body[] = 'Content-MD5: '.$base64.'';
$body[] = 'Content-Length: '.filesize($path).'';
$body[] = 'Content-Type: '.$mime.'';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://upload.smugmug.com/');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_error ($ch);
$result = curl_exec($ch);
print_r($result);
使用OAuth可能很棘手,SmugMug的上传API有点独特。使用其中一个PHP包装器可能会有所帮助,而不是编写自己的代码。下面是两个示例,它们都有如何上载图像的示例: 1.) (二) 例如,使用DFM Smug包装器,可以执行以下操作(从包装器附带的自述文件复制):
使用OAuth可能很棘手,SmugMug的上传API有点独特。使用其中一个PHP包装器可能会有所帮助,而不是编写自己的代码。下面是两个示例,它们都有如何上载图像的示例: 1.) (二) 例如,使用DFM Smug包装器,可以执行以下操作(从包装器附带的自述文件复制):
<?php
require_once("dfm-smug-wrapper/dfm-smug-wrapper.php");
$f = new DFM_Smug(
"oauth_consumer_key=12345678",
"oauth_secret=some_secret",
"token_id=12345",
"token_secret=some_other_secret",
"app_name=My Cool App/1.0 (http://app.com)",
"api_ver=2.0"
);
$f->images_upload("AlbumID=123456", "File=/path/to/image.jpg");
?>