我应该多久看一次“因401而刷新”和“刷新access_token”

时间:2012-09-01 15:34:35

标签: google-drive-api

我在任务队列中有一个Google App Engine任务,对我的应用最近上传到Google云端硬盘帐户的文件以及通过调整原件大小创建的新文件执行以下四个步骤。

1- file = service.files().get(fileId=googleDriveFileId).execute()

2- resizedImage = resizeImage(theImage,currentWidth,currentHeight,135,90);
   newImage = putGoogleDriveFile(user,resizedImage,imageName,'image/jpeg',None,"image")

3- service.permissions().insert(fileId=file_id, body=new_permission).execute()

4- service.files().delete(fileId=googleDriveFileId).execute()

所有步骤都有效,所有文件都应该具有正确的权限等等。

但是,我的日志文件显示每个步骤都刷新了access_token。

 URL being requested: https://www.googleapis.com/discovery/v1/apis/drive/v2/rest?userIp=0.1.0.2
2012-09-01 07:51:10.578 URL being requested: https://www.googleapis.com/drive/v2/files/0Bx4nwQIkoY_7OVE4U3JtcUVPMzQ?alt=json
2012-09-01 07:51:10.602 Refreshing due to a 401
2012-09-01 07:51:10.602 Refresing access_token
2012-09-01 07:51:11.222 putting drive file
2012-09-01 07:51:11.231 have credentials
2012-09-01 07:51:11.232 URL being requested:  https://www.googleapis.com/discovery/v1/apis/drive/v2/rest?userIp=0.1.0.2
2012-09-01 07:51:11.478 URL being requested: https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json
2012-09-01 07:51:11.505 Refreshing due to a 401
2012-09-01 07:51:11.505 Refresing access_token
2012-09-01 07:51:13.676 setting permissions
2012-09-01 07:51:13.682 have credentials
2012-09-01 07:51:13.684 URL being requested: https://www.googleapis.com/discovery/v1/apis/drive/v2/rest?userIp=0.1.0.2
2012-09-01 07:51:13.777 URL being requested: https://www.googleapis.com/drive/v2/files/0Bx4nwQIkoY_7dXhUbWdLaU9feUU/permissions?alt=json
2012-09-01 07:51:13.803 Refreshing due to a 401
2012-09-01 07:51:13.803 Refresing access_token
2012-09-01 07:51:14.484 have credentials
2012-09-01 07:51:14.485 URL being requested: https://www.googleapis.com/discovery/v1/apis/drive/v2/rest?userIp=0.1.0.2
2012-09-01 07:51:14.656 URL being requested: https://www.googleapis.com/drive/v2/files/0Bx4nwQIkoY_7UUJadzNGa2oxRjA
2012-09-01 07:51:15.098 Refreshing due to a 401
2012-09-01 07:51:15.098 Refresing access_token

这是我应该期待的吗?在我看来,在一个循环中运行的四个动作的一个access_token就足够了。

谢谢, 克里斯

1 个答案:

答案 0 :(得分:1)

典型的access_token持续一个小时。我的猜测是每个请求仍然使用过期的令牌而不是闪亮的新令牌。