我有一个php文件“yotpo_authentication.php”,它与api交互以使用curl进行身份验证:
<?php
$yotpo_keys = array(
"client_id"=> "myid",
"client_secret"=> "mysecret",
"grant_type"=> "client_credentials"
);
$ch = curl_init( "https://api.yotpo.com/oauth/token" );
# Setup request to send json via POST.
$payload = json_encode( $yotpo_keys );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
$yotpo_token_array = json_decode($result, true);
echo $yotpo_token_array[access_token];
?>
现在我的下一步是在我用来与api交互的第二个php文件中使用我被回复的用户令牌(access_token):
<?php
require ('yotpo_authentication.php');
?>
<?php
$yotpo_platform = json_decode('{
"account_platform": {
"shop_domain": "http://testsitemm.com",
"platform_type_id": "2"
},
"utoken": '. $yotpo_token_array[access_token].'"
} ');
$ch = curl_init( " https://api.yotpo.com/apps/myapikey/account_platform" );
# Setup request to send json via POST.
$payload = json_encode( $yotpo_platform );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
$yotpo_token_array = json_decode($result, true);
所以我相信我有2个问题: