2

PHPでモデルを更新しようとしています。トレーニングと予測はできますが、更新はできません。PUT を使用していることが原因かもしれませんが、問題が見つかりません。コードは次のとおりです。

$authCode = $_GET['token'];
$man =$_GET['owner'];
$type = $_GET['type'];
$title= $_GET['title'];
$id = "*****";

$api_key = "**********************";
$url =  "https://www.googleapis.com/prediction/v1.4/trainedmodels/".$id."?pp=1&key=".$api_key;
$header = array('Content-Type:application/json','Authorization: OAuth '.$authCode);


$str = "label=dislike&csvInput[]=video&csvInput[]=war&csvInput[]=john";
parse_str($str, $output);

$putData = tmpfile();
fwrite($putData, $output);
fseek($putData, 0);    

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $putData); 
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($output));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

応答:

HTTP/1.1 400 Bad Request Content-Type: アプリケーション/json; charset=UTF-8 Date: Sat, 07 Jan 2012 19:25:32 GMT Expires: Sat, 07 Jan 2012 19:25:32 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked { "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "Parse Error" } ], "コード": 400、"メッセージ": "解析エラー" } }

4

3 に答える 3

2

Google API PHP ライブラリhttp://code.google.com/p/google-api-php-client/を使用することをお勧めします 。これには、モデルを更新するためのメソッドが組み込まれています。

それはあなたに多くの手間を省きます。

于 2013-04-23T11:47:59.920 に答える
0

I've found the solution. here is the code that need changes:

$output = json_encode($requestBody);
$putData = tmpfile();
fwrite($putData, $output);
fseek($putData, 0);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $putData); 
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($output));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
于 2012-01-07T19:41:45.687 に答える
0

この行で:

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

ID の後と疑問符の前にスラッシュがないようです。代わりにこれを試してください:

$url =  "https://www.googleapis.com/prediction/v1.4/trainedmodels/".$id."/?pp=1&key=".$api_key;
于 2012-01-06T01:57:52.327 に答える