400 Bad Request on Gmail API with php

后端 未结 1 1198
遥遥无期
遥遥无期 2021-01-28 16:54

I want my server to access a gmail account with php code. And the following is what I created with the examples I can find online.



        
相关标签:
1条回答
  • 2021-01-28 17:32

    You should not be using a service account if you just want to access one account (your own). Service accounts are their own account and they're not Gmail accounts. They work well for APIs that don't need a user (e.g. maps, search) or when you are using a Google Apps for Work domain and want delegation enabled for all users in the domain (by domain admin, so you don't need individual user authorization).

    You want to use standard oauth2 web auth flow. If you want to make sure it's usable offline (e.g. by some script/service/cron job) then make sure you add the offline flag on your oauth2 authorization web flow request and that'll make sure you get a permanent refresh token (can be used to request an access token). If you don't set offline, then it's an access token which is only good for an hour. See https://developers.google.com/gmail/api/auth/web-server for more details.

    0 讨论(0)
提交回复
热议问题