Tag: google oauth

Google表格API v4 service_account – 禁止:来电者没有权限(Google :: Apis :: ClientError)

Ruby:2.3.1 Rails:5.0.0 我需要通过Google表格API访问和更新我的私人Google表格。 最终,这应该由我的Rails应用程序中的重复后台作业完成。 因此,我在Google云端控制台中设置了服务帐户。 但是要开始使用Google表格API,我创建了一个脚本: require ‘google/apis/sheets_v4’ ENV[“GOOGLE_ACCOUNT_TYPE”] = ‘service_account’ ENV[“GOOGLE_CLIENT_EMAIL”] = ” ENV[“GOOGLE_PRIVATE_KEY”] = “” SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS authorization = Google::Auth.get_application_default(SCOPE) # Initialize the API service = Google::Apis::SheetsV4::SheetsService.new service.authorization = authorization spreadsheet_id = ” sheet_name = ‘Sheet1’ range = “#{sheet_name}!A2:B” response = service.get_spreadsheet_values(spreadsheet_id, range) puts ‘No data found.’ if response.values.empty? response.values.each do |row| […]

使用XOAUTH2访问Google域用户电子邮件数据

我正在尝试使用xoauth2从我们的谷歌应用程序访问我们的学生gmail数据。 我一直在这个区域,googles文档的组织非常糟糕,而且还有很多旧的文档不再适用于你所指向的,所以它很有趣。 我基本上使用我创建的已启用域委派的服务帐户在python中使用googles oauth2client来使用以下代码。 from oauth2client.client import SignedJwtAssertionCredentials client_email = ‘serviceaccount@developer.gserviceaccount.com’ with open(“testserviceaccount.p12”) as f: private_key = f.read() credentials = SignedJwtAssertionCredentials(client_email, private_key, ‘https://www.googleapis.com/auth/gmail.readonly’, sub=’student email address’) from httplib2 import Http http_auth = credentials.authorize(Http()) from apiclient.discovery import build service = build(‘gmail’, ‘v1′, http=http_auth ) messages = service.users().messages().list(userId=’student email address’).execute() print messages 我需要这个应用程序的应用程序是在轨道上的ruby,所以我正在寻找任何提示或帮助在Ruby on Rails中使用什么来实现相同的效果。 任何帮助或提示非常感谢。