标签: gmail-api

试图在Python中运行Gmail API快速入门的属性错误

看起来这里可能存在版本不匹配问题.我该怎么办呢?

我尝试用pip更新六个,但这没有做任何事情.

这是我看到的错误:

Traceback (most recent call last):
  File "./quickstart.py", line 27, in <module>
    credentials = run(flow, STORAGE, http=http)
  File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/oauth2client/old_run.py", line 120, in run
    authorize_url = flow.step1_get_authorize_url()
  File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 1827, in step1_get_authorize_url
    return _update_query_params(self.auth_uri, query_params)
  File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 435, in _update_query_params
    parts = urllib.parse.urlparse(uri)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
Run Code Online (Sandbox Code Playgroud)

python oauth-2.0 gmail-api

18
推荐指数
2
解决办法
6919
查看次数

Google :: Apis :: AuthorizationError(未经授权)

我们正在创建一个以Ionic框架作为前端和Ruby on Rails作为后端的应用程序.我们可以在我们的应用中关联Gmail帐户.帐户链接工作正常,我们从前端获取serverAuthCode,然后使用它获取刷新令牌,我们可以在第一次尝试时使用该刷新令牌获取电子邮件.但在几秒钟内,它就会过期或被撤销.得到以下问题:

Signet::AuthorizationError (Authorization failed.  Server message:
{
  "error" : "invalid_grant",
  "error_description" : "Token has been expired or revoked."
})
Run Code Online (Sandbox Code Playgroud)

看起来,刷新令牌本身就会在几秒钟内到期.有没有人知道如何解决它?

更新:

现有代码如下所示:

class User   
  def authentication(linked_account)
    client = Signet::OAuth2::Client.new(
    authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
    token_credential_uri: Rails.application.secrets.token_credential_uri,
    client_id: Rails.application.secrets.google_client_id,
    client_secret: Rails.application.secrets.google_client_secret,
    scope: 'https://www.googleapis.com/auth/gmail.readonly, https://www.googleapis.com/auth/userinfo.email, https://www.googleapis.com/auth/userinfo.profile',
    redirect_uri: Rails.application.secrets.redirect_uri,
    refresh_token: linked_account[:refresh_token]
  )

  client.update!(access_token: linked_account.token, expires_at: linked_account.expires_at)
  return  AccessToken.new(linked_account.token) unless client.expired?
  auth.fetch_access_token! 
 end

 def get_email(linked_account)
   auth = authentication(linked_account)
   gmail = Google::Apis::GmailV1::GmailService.new
   gmail.client_options.application_name = User::APPLICATION_NAME
   gmail.authorization = AccessToken.new(linked_account.token)
   query = "(is:inbox OR is:sent)"
   gmail.list_user_messages(linked_account[:uid], …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails google-client google-oauth gmail-api

18
推荐指数
1
解决办法
1669
查看次数

使用Gmail API从PHP中读取Gmail中的邮件

我已经从Google PHP客户端库中下载了新的Gmail API源代码.

我使用以下方法启动了服务:

set_include_path("./google-api-php-client-master/src/".PATH_SEPARATOR.get_include_path());

require_once 'Google/Client.php';   
require_once 'Google/Service/Gmail.php';

$client = new Google_Client();
$client->setClientId($this->config->item('gmailapi_clientid'));
$client->setClientSecret($this->config->item('gmailapi_clientsecret'));
$client->setRedirectUri(base_url('auth'));
$client->addScope('email');
//$client->addScope('profile');     
$client->addScope('https://mail.google.com');           
$client->setAccessType('offline');

$gmailService = new Google_Service_Gmail($client);
Run Code Online (Sandbox Code Playgroud)

接下来我该怎么办?如何使用Gmail API PHP库阅读Gmail邮件?

gmail-api

17
推荐指数
3
解决办法
3万
查看次数

使用gmailr发送HTML消息

我希望能够使用gmailR包通过内联电子邮件(而不是附件)发送R生成的HTML报告.我甚至无法使用发送基本的HTML电子邮件gmailr.我尝试了下面的失败并需要一些帮助:

library(gmailr)
gmail_auth("oauth.token.json", scope = "compose")

test_email <- mime() %>%
 to("you@gmail.com") %>%
 from("me@gmail.com") %>%
 subject("This is a subject") 
test_email$body <- "I wish <b>this</b> was bold"
send_message(test_email)
Run Code Online (Sandbox Code Playgroud) 结果:消息成功发送,但正文是纯文本 - 而不是HTML


尝试2

test_email <- mime() %>%
 to("you@gmail.com") %>%
 from("me@gmail.com") %>%
 subject("This is a subject") %>%
 html_body("I wish <b>this</b> was bold")
test_email$body
Run Code Online (Sandbox Code Playgroud) 结果:test_email $ body为NULL


尝试3

test_email <- mime() %>%
 to("you@gmail.com") %>%
 from("me@gmail.com") %>%
  subject("This is a subject") 
test_email$body <- html_body("I wish <b>this</b> was bold")
Run Code Online (Sandbox Code Playgroud) 结果:mime $ parts中的错误:$ operator对原子向量无效


尝试4

test_email …
Run Code Online (Sandbox Code Playgroud)

r gmail-api gmailr

17
推荐指数
1
解决办法
2470
查看次数

使用Google Spreadsheet API在Google中的Google驱动器中创建电子表格

我创建了一些填充谷歌电子表格的工具.它工作正常1年,因为今天我错了

Exception in thread "main" com.google.gdata.util.AuthenticationException: Error authenticating (check service name)
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory.java:688)
at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:560)
at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:397)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:364)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:319)
at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:303)
Run Code Online (Sandbox Code Playgroud)

这是与gmail连接的代码部分:

String USERNAME = "usename@........com"; ->of course I'm using proper username and password
    String PASSWORD = "*******";
    SpreadsheetService service
            = new SpreadsheetService("SandboxCheck");
    service.setUserCredentials(USERNAME, PASSWORD);
Run Code Online (Sandbox Code Playgroud)

我不知道如何连接gmail,我试图通过oAuth这样做,但我不知道如何做到这一点.在https://developers.google.com/google-apps/spreadsheets/authorize上的示例中,只有.net的代码.

java google-api google-sheets gmail-api

17
推荐指数
1
解决办法
1万
查看次数

如何使用Gmail API访问我拥有的Gmail帐户?

我想将节点脚本作为cronjob运行,它使用Gmail的API来轮询我拥有的Gmail帐户.

我正在按照这些快速入门说明操作:

快速开始

我坚持第一步.在请求cron脚本的凭据时,它告诉我"无法从没有UI的平台访问用户数据,因为它需要用户交互才能登录":

在此输入图像描述

这些文档总体上令人困惑,并提到"服务帐户","OAuth"和其他内容 - 我无法分辨哪些适用于我的用例,哪些不适用.我使用了许多SaaS API,典型的工作流程是登录您的帐户,获取API密钥和密钥,并使用脚本中的API访问API.这似乎不是 Gmail API使用的范例,所以我很感激任何指导或指向更清晰指示的链接.

gmail gmail-api

17
推荐指数
1
解决办法
8209
查看次数

无法在新的Gmail用户界面中打开通过Gmail REST API发送的电子邮件/草稿

通过Gmail REST API发送草稿时,发件人无法在新的Gmail用户界面中打开"已发邮件"文件夹中的邮件.您收到错误消息"The conversation that you requested could not be loaded.".

接收方的消息可以毫无问题地打开,无论是否有新UI.

恢复旧的/经典Gmail用户界面允许发件人打开已发送的邮件.

重现步骤:

  1. 在Gmail中撰写草稿(新旧UI无关紧要)
  2. 通过查找草稿ID GET https://www.googleapis.com/gmail/v1/users/me/drafts
  3. 通过POST https://www.googleapis.com/gmail/v1/users/me/drafts/send正文发送草稿{"id": "<draftId>"}
  4. 返回Gmail并切换到新的Gmail用户界面,然后尝试在"已发送"文件夹中打开最近发送的草稿.尝试打开邮件将失败.
  5. 恢复旧的/经典Gmail用户界面并在"已发送"文件夹中打开最近发送的草稿.您将能够毫无问题地打开邮件.
  6. 使用新的或旧的UI,收件人将能够毫无问题地打开邮件.

UPDATE

当损坏的已发送电子邮件收到回复后,它似乎已"修复",发件人现在可以从新的Gmail用户界面打开已发送的电子邮件.这似乎表明REST API缺少一些线程通过其他方式更新后得到修复的东西?

尝试打开已损坏的已发送邮件时,浏览器控制台中的错误消息:

Error: Ppa No message loaded when we received the DETAILED_CONVERSATION_MESSAGES_LOADED event.

gmail gmail-api

17
推荐指数
1
解决办法
380
查看次数

当我或其他用户尝试使用OAuth2进行授权时,我不断收到我的应用需要验证的错误.那是什么意思?

尝试使用我自己的帐户授权我的应用时收到此错误:

Your project is trying to access scopes that need to go through the verification process.

{invalid=https://www.googleapis.com/auth/contacts}

If you need to use one of these scopes, submit a verification request. Learn More
Run Code Online (Sandbox Code Playgroud)

当我使用其他帐户时,错误消息是不同的:

This app hasn’t been verified to access:
{invalid=https://www.googleapis.com/auth/contacts}


Are you the developer? If this project needs these scopes, sign in to an account with access to edit your project and try again.

If not, contact the developer for help.
Run Code Online (Sandbox Code Playgroud)

google-api google-contacts-api google-oauth gmail-api

16
推荐指数
1
解决办法
6872
查看次数

尝试通过服务帐户发送电子邮件,获取com.google.api.client.auth.oauth2.TokenResponseException:401 Unauthorized

我有一个Google Apps帐户.我正在尝试使用服务帐户代表用户发送电子邮件.

我已经浏览了互联网,没有任何工作,我几乎不知所措.

我跟着Java指南,我仍然继续 com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized

为什么这段代码片段给我401 Unauthorized?

JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

            GoogleCredential credential = new GoogleCredential.Builder()
                    .setTransport(httpTransport)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId("something@something-something.iam.gserviceaccount.com")
                    .setServiceAccountPrivateKeyFromP12File(new File("path/to/file/myProject.p12"))
                    .setServiceAccountScopes(GmailScopes.all())
                    .setServiceAccountUser("user@mydomain.org")
                    .build();

Gmail gmailService = new Gmail.Builder(httpTransport, JSON_FACTORY, credential)
                    .setApplicationName("My App") // DOES IT MATTER WHAT THIS IS SET TO?
                    .build();

MimeMessage mimeMessage = createEmail("myemail@gmail.com", "user@mydomain.org", "Testing", "hey");
sendMessage(gmailService, "me", mimeMessage);
Run Code Online (Sandbox Code Playgroud)

这些方法基本上是从Googles文档中复制/粘贴的:

/**
     * Create a MimeMessage using the parameters provided.
     *
     * @param to email address of the receiver
     * @param …
Run Code Online (Sandbox Code Playgroud)

authentication oauth google-api google-apps gmail-api

14
推荐指数
1
解决办法
821
查看次数

Gmail邮件ID或ThreadId如何映射到新的Gmail用户界面?

编辑:解决下面的第一条评论,为清楚起见,这不是代码问题.问题很简单:

我应该在新的Gmail用户界面的URI查询字符串中添加什么来查看Gmail API创建的草稿邮件?

尽管这不是一个代码问题,但我要求Stack Overflow作为Google首选的Gmail API问题平台.

-

如果我在新的Gmail用户界面中查看草稿邮件,则URI如下所示:

https://mail.google.com/mail/u/1/?zx=iij9apqgzdf4#drafts?compose=jrjtXSqXwlFGnSGCQgDCdnHGVFdlpFMgzsCNgpQstQLxdLCMkjKstBmWZkCmjhWTQnpsZCJF

我看不到通过Gmail API创建的邮件的ID或ThreadId创建此类链接的任何方法.

以前,人们可以这样做:

https://mail.google.com/mail/u/1/?zx=ov61dxfbrcga#drafts?compose=1631caae9dbb074d

其中"compose"的值是Id.

如何在新UI中完成同样的事情?

gmail gmail-api

14
推荐指数
2
解决办法
1754
查看次数