0
私はcURLを使用していくつかのAPI作業をしています。PHP - curl_execから特定の値を取得
HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Thu, 29 Jun 2017 18:31:37 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 316 Connection: close {"message":"SUCCESS","resultCode":0,"result":{"id":348293483294,"name":"smartsheet.png","attachmentType":"FILE","mimeType":"image/png","sizeInKb":85,"parentType":"ROW","parentId":32423423423,"createdBy":{"name":"Test","email":"[email protected]"},"createdAt":"2017-06-29T18:31:37Z"},"version":404}
がどのように私は、この応答からPARENTIDに関連付けられた値にアクセスすることができます
$headers = array(
'Authorization: Bearer '. $accessToken,
'Content-Type: image/png',
'Content-Disposition: attachment; filename="'. $filename .'"',
'Content-Length: '. $fileSize
);
$curlSession = curl_init($apiURL);
curl_setopt($attachmentSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($attachmentSession, CURLOPT_HEADER, true);
curl_setopt($attachmentSession, CURLOPT_INFILE, $fileStream);
curl_setopt($attachmentSession, CURLOPT_INFILESIZE, $fileSize);
curl_setopt($attachmentSession, CURLOPT_UPLOAD, 1);
//curl_setopt($attachmentSession, CURLOPT_POSTFIELDS, '');
curl_setopt($attachmentSession, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($attachmentSession, CURLOPT_CUSTOMREQUEST, "POST");
$curlResponse = curl_exec($curlSession);
print_r($curlResponse);
これは私に次のような出力が得られます。私はこのようなセッション応答をログアウトしていますか?私は、次のことを試してみました:
$curlResponse->parentId
と
$curlResponse[parentId]
が、それらは動作しませんでした。
残りのカールの設定はどこですか?ヘッダーも取得するオプションを設定する必要があります。そのオプションと 'json_decode'を使わずに試してみてください。 – dan08
@ dan08は私のカールの残りの部分で更新されました – user13286
@ dan08ありがとうございました! 'CURLOPT_HEADER'行を削除したら、' json_decode'を使うことができました。答えとして追加してください、もう一度ありがとう! – user13286