GoogleAdwordsAPIを使う。

Oauth2の認証が肝。
developerTokenとclient_id・client_secret・redirect_uriを設定したらAPIのexampleにあるGetRefreshToken.phpaccess_codeを取得するためのURLを作る。
ttps://accounts.google.com/o/oauth2/auth?response_type=code&client_id=「client_id」&redirect_uri=「redirect_uri(要URLエンコード)」&scope=https%3A%2F%2Fadwords.google.com%2Fapi%2Fadwords%2F&access_type=offline
別に無くても作れるのかもしれない。あと試す為にxamppでちゃんと動かないので一部直して動かす。
URLにアクセスするとコールバックURIにGET変数つきで帰ってくる。
たとえ存在しないページでもURLにcode=〜〜〜〜〜〜〜〜〜〜となるのでその部分。

つぎはそれを設定してrefresh_tokenを取得。
https://accounts.google.com/o/oauth2/tokenに対して
code=さっきのaccess_code
client_id = 登録済みのclient_id
client_secret = 登録済みのclient_secret
redirect_uri = 登録済みのredirect_uriエンコード不要)
grant_type = 固定文字列で"authorization_code"

の値を設定してPOSTで送信。curlで。

$test = curl_init();
$curl_param = array(
"code" => 「access_code」,
"client_id" => 「client_id」,
"client_secret" => 「client_secret」,
"redirect_uri" => 「redirect_uri」,
"grant_type" => "authorization_code"
);
curl_setopt($test, CURLOPT_URL,"https://accounts.google.com/o/oauth2/token");
curl_setopt($test, CURLOPT_POST, true);
curl_setopt($test, CURLOPT_POSTFIELDS, $curl_param);
curl_setopt($test, CURLOPT_HTTPAUTH, CURLAUTH_ANY);//認証方法は順次試す
curl_setopt($test, CURLOPT_SSL_VERIFYPEER, false);//証明書の検証はしない
curl_setopt($test, CURLOPT_RETURNTRANSFER, 1);//戻り値を文字列で受け取る

$res = curl_exec($test);
echo $res;
curl_close($test);

で取得した中にあるrefresh_tokenを使う。と。