Reply to Thread Google-Api-Ruby-Client

reply to thread google-api-ruby-client

Looking at the source on GitHub for send_user_message shows that it doesn't take a thread_id as a parameter. However the Message class does have it as an attribute.

So perhaps trying this should work:

  service ||= Google::Apis::GmailV1::GmailService.new

message = RMail::Message.new
message.header['To'] = params[:gmail][:to]
message.header['From'] = current_user_google_user_id
message.header['Subject'] = params[:gmail][:subject]
message.header['Subject'] = params[:gmail][:subject]
message.body = params[:gmail][:body]
message.thread_id = params[:gmail][:thread_id]

service.send_user_message(
current_user_google_user_id,
upload_source: StringIO.new(message.to_s),
content_type: 'message/rfc822'
)

Google-api-ruby-client Translate API Examples

Code for making calls to the translate API looks like this:

require 'google/api_client'
client = Google::APIClient.new(:key => YOUR_DEVELOPER_KEY)
translate = client.discovered_api('translate', 'v2')
result = client.execute(
:api_method => translate.translations.list,
:parameters => {
'format' => 'text',
'source' => 'en',
'target' => 'es',
'q' => 'The quick brown fox jumped over the lazy dog.'
}
)

Download a file from Google Drive using google-api-ruby-client

From the error that you got, it says that your request is invalid. So make sure that your request there are correct. Here is the documentation on how to download files using Ruby(just click the Ruby on the example to view the ruby code.)

Take NOTE: Downloading the file requires the user to have at least
read access. Additionally, your app must be authorized with a
scope
that allows reading of file content.

For more information, check these threads:

  • How to download file from google drive api

  • A Ruby library to read/write files

Error 500 Adding Thumbnails with Youtube API v3

Not all channels are enabled for custom thumbnails; I suspect that if you're getting an error, it might be because you're attempting to set a custom thumbnail for a video in a channel that isn't enabled. There's more info at https://support.google.com/youtube/answer/72431?hl=en

Could you follow the steps in that help article and see whether you have an option in the web UI to set a custom thumbnail? If you don't, then your channel isn't enabled.

Getting back a HTTP 500 response is obviously unhelpful, though, and makes it difficult to confirm that that's what's going on. We can follow up with the engineering team about that to get a helpful error returned once we confirm whether your channel is enabled or not.

Unauthorized client error when using domain wide delegation with Google API

So I have finally figured out where the problem was.
Among other scopes I also enabled these:

http://www.google.com/m8/feeds/contacts/ 
http://www.google.com/m8/feeds/groups/

Turns out Google probably invalidated them and they now require https instead of http.

It would be nice if they provided better error message, something like that entered scopes are invalid when authorizing them in Google Admin Console.

I found the mistake when trying to authorize normal OAuth2 Client ID for the same scopes as I used for the service account. The OAuth2 consent screen shows proper error message.

Update

Here is the checklist I created for troubleshooting service accounts errors:

  1. Check that Domain Wide Delegation is enabled for service account in Google Cloud Console.
  2. Check that you entered the proper scopes in Google Admin Console with service account's Client ID (not its email!). Make sure all the scopes are valid! They might become invalid during their lifetime. When you enter invalid scope you get unauthorized_client error when fetching access token even for valid scope.


Related Topics



Leave a reply



Submit