Trouble with Google Apps API and Service Accounts in Ruby

后端 未结 3 536
野性不改
野性不改 2021-01-14 07:44

I\'m having some trouble getting the sample code for instantiating a Drive Service Account working. I\'ve set up the service account in the API console as directed and inclu

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 07:51

    This looks to me like you are using an older example. I think that's how you used to do it about a year ago. Back in late 2012 that method of setting up the app was deprecated because Signet was updated to handle all aspects of the OAuth2 setup.

    Here is the code I generally use to create a service account. You can tweak it to fit into your method.

    client.authorization = Signet::OAuth2::Client.new(
     :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
     :audience => 'https://accounts.google.com/o/oauth2/token',
     :scope => "https://www.googleapis.com/auth/drive",
     :issuer => "@developer.gserviceaccount.com",
     :signing_key => Google::APIClient::KeyUtils.load_from_pkcs12("-privatekey.p12", "notasecret"),
     :person => "")
    client.authorization.fetch_access_token!
    

    If you are still having issues let me know and I'll see if I can help.

提交回复
热议问题