0

PHPでGooglePredictionを使用しようとしています。すでにOAuth2.0で認証を行っていますが、モデルをトレーニングしたいと思います。Prediction Explorer(http://code.google.com/apis/explorer/#_s=prediction&_v=v1.4&_m=trainedmodels.insert)の例に従おうとしているので、PHPでは次のようにします。

$authCode = $_REQUEST['token'];
$id = $_REQUEST['id'];
$storageDataLocation = $_REQUEST['storageDataLocation'];
$api_key = "AIzaSyAIs5*************************";

$url =  "https://www.googleapis.com/prediction/v1.4/trainedmodels?pp=1&key=".$api_key;

$header = array('Content-Type:application/json',
                       'Authorization: OAuth = '.$authCode,
                       'X-JavaScript-User-Agent:  Google APIs Explorer google-api-gwt-client/0.1-alpha');


$success = "";


$data = array($id, $storageDataLocation);

$jsonData = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$ss = curl_exec($ch);
print_r($ss);

$response = json_decode();

if(!$response->{'data'}->{'data'}==$id){
           $success = $response->{'data'}->{'data'};
}
error_log("Training invocation result: ". $success);
echo $success;

そして、そのprint_r($ ss)は私にこれを与えます:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

私はどこが間違っていますか?

4

0 に答える 0