1

https://build.phonegap.com/docs/apiにある API を使用して phonegap アプリケーションを構築したい

トークンを返す次の curl コマンドを実行する必要があります。

$ curl -u andrew.lunny@nitobi.com -X POST "" https://build.phonegap.com/token

このcurlステートメントは、コマンドラインで機能しています。phpで使いたいです。以下のphpコードを試しましたが、うまくいきません。

$username = "USERNAME@gmail.com";
$password = "PASSWORD";
$target_url = "https://build.phonegap.com/token"

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result = curl_exec($ch);
curl_close ($ch);
echo $result;
4

2 に答える 2

1

shell_exec()次の機能を試すこともできます。

$cmd = "curl -u andrew.lunny@nitobi.com -X POST "" https://build.phonegap.com/token";
$out = shell_exec($cmd);
$data = json_decode($out);
于 2012-11-26T14:31:24.580 に答える
0

私は解決策を見つけました。

ローカルホストの設定に問題があります。コードを Web サーバーにアップロードすると、動作し始めました。

于 2012-09-04T22:20:28.613 に答える