Google API的oauth_signature生成

时间:2011-08-24 17:28:06

标签: php oauth google-api

我正在尝试为我的网站获取用户的联系人,但我无法从谷歌获得令牌,因为我收到了无效的oauth签名错误。任何人都可以告诉我如何在PHP中为谷歌生成oauth签名。

谢谢:)

1 个答案:

答案 0 :(得分:1)

这就是我从谷歌分析中获取数据的方法

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, 'https://www.google.com/accounts/ClientLogin');
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_POST, TRUE);
  $data = array(
    'accountType' => 'GOOGLE',
    'Email' => $email, //your google email
    'Passwd' => $password, //your google pass
    'service' => 'analytics',
    'source' => 'curl-accountFeed-v2'
    );
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  $response = curl_exec($curl);
  $info = curl_getinfo($curl);
  curl_close($curl);
  if ($info['http_code'] == 200) {
   if ($response) {
     preg_match('/Auth=(.*)/', $response, $matches);
     if (isset($matches[1])) {
       $auth_code = $matches[1];
     }
   }
  }