dongqian9567 2014-04-09 21:38
浏览 41
已采纳

PHP:我可以使用帐户和密码来授权google-api-client连接吗?

In Google Docs api guide, Oauth2 are provided as an authorization method. Here are the authorization code:

$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('...');
$client->setClientSecret('...');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));

$service = new Google_DriveService($client);

$authUrl = $client->createAuthUrl();

// Request authorization
print "Please visit:
$authUrl

";
print "Please enter the auth code:
";
$authCode = trim(fgets(STDIN));

// Exchange authorization code for access token
$accessToken = $client->authenticate($authCode);
$client->setAccessToken($accessToken);

However, this kind of authorization requires you to click the link and authorize it manually. What I want is to use email account and password to authorize the connection, is that possible?

BTW, I do not want to use Zend-Gdata. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doutuoben6908 2014-04-10 00:28
    关注

    You can use a service account.

    For these types of server-to-server interactions you need a service account, which is an account that belongs to your application instead of to an individual end-user. Your application calls Google APIs on behalf of the service account, and user consent is not required. (In non-service-account scenarios, your application calls Google APIs on behalf of end-users, and user consent is sometimes required.)

    Here's a sample code using the PHP lib.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示