我試圖測試此示例,我發現here以便我可以在客戶端直接上傳,而無需用戶使用Google雲端存儲進行登錄。提供的關鍵參數不能強制轉換爲使用Google API的私鑰
所有表達的常量都有它們的正確值,路徑是正確的,沒有空的內容。
我得到的錯誤:
openssl_sign(): supplied key param cannot be coerced into a private key
我的功能實現的是:
public static function storageURL($id, $method = 'GET', $duration = 10) {
$key = file_get_contents(self::KEY_FILE);
$pkey = openssl_get_privatekey($key, 'notasecret');
$expires = time() + $duration;
$content_type = ($method == 'PUT') ? 'application/x-www-form-urlencoded' : '';
$to_sign = ($method . "\n" .
/* Content-MD5 */ "\n" .
$content_type . "\n" .
$expires . "\n" .
'/'.self::BUCKET_NAME.'/' . $id);
$signature = '*Signature will go here*';
if (!openssl_sign($to_sign, $signature, $pkey, 'sha256'))
{
error_log('openssl_sign failed!');
$signature = '<failed>';
} else {
$signature = urlencode(base64_encode($signature));
}
return ('https://'.self::BUCKET_NAME.'.commondatastorage.googleapis.com/' .
$id .
'?GoogleAccessId=' . self::SERVICE_ACCOUNT_NAME .
'&Expires=' . $expires . '&Signature=' . $signature);
}
這樣我就可以只使用這生成URL的? – RyanDawkins
什麼是「這個」?如果你的意思是google-api-php-client,那麼是的 – jterrace
哦......你在哪裏找到api-library的文檔? – RyanDawkins