Tag: 谷歌的API ruby客户端

通过Gmail API创建包含收件人的Gmail草稿

我一直试图弄清楚如何自动将收件人添加到使用Gmail API通过其Ruby库创建的草稿电子邮件中。 我可以创建草案而没有任何问题,但设置收件人会给我带来麻烦,我无法找到任何好的示例,显示添加电子邮件特定事物的最佳方法。 使用Google API游乐场并提取已经创建的草稿,看起来结构应该与下面显示的类似,但是无论何时创建草稿,都没有收件人。 @result = client.execute( :api_method => gmail.users.drafts.create, :parameters => { ‘userId’ => “me” }, :body_object => { ‘message’ => { ‘raw’ => Base64.urlsafe_encode64(‘Test Email Message’), ‘payload’ => { ‘headers’ => [ { ‘name’ => “To”, ‘value’ => “John Smith ” } ] } } } )

使用Ruby中的Google Apps API和服务帐户时出现问题

我在获取用于实例化Drive Service帐户的示例代码时遇到了一些麻烦。 我已按照指示在API控制台中设置服务帐户,并包含“ https://www.googleapis.com/auth/drive ”的范围,但运行此操作会生成以下错误:“授权失败。服务器消息:(Signet :: AuthorizationError)“。 奇怪的是,如果我省略user_email地址,它不会产生错误。 我的目标是能够对组织的驱动器上存储的所有文件进行审核,我的理解是使用服务帐户将获得存储的所有文件的列表。 我是否错过了服务器端的一些特殊设置? require ‘google/api_client’ ## Email of the Service Account # SERVICE_ACCOUNT_EMAIL = ‘@developer.gserviceaccount.com’ ## Path to the Service Account’s Private Key file # SERVICE_ACCOUNT_PKCS12_FILE_PATH = ‘-privatekey.p12’ def build_client(user_email) key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, ‘notasecret’) asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, ‘https://www.googleapis.com/auth/drive’, key) client = Google::APIClient.new client.authorization = asserter.authorize(user_email) return client end […]

通过Google Gmail API创建草稿

我正在尝试为登录用户创建草稿消息,但在运行以下内容时不断收到错误Missing draft message require ‘google/api_client’ client = Google::APIClient.new client.authorization.client_id = ENV[‘GOOGLE_CLIENT_ID’] client.authorization.client_secret = ENV[‘GOOGLE_CLIENT_SECRET’] client.authorization.grant_type = ‘refresh_token’ client.authorization.refresh_token = User.last.refresh_token token = client.authorization.fetch_access_token! gmail = client.discovered_api(‘gmail’, ‘v1’) params = { ‘userId’ => ‘me’, ‘draft’ => { ‘message’ => {‘raw’ => ‘test email’ } } } # { ‘userId’ => ‘me’, ‘message’ => {‘raw’ => ‘test […]