Question

I already have the login (OAuth) piece working with my app, what I am trying to do now is pull down the authenticated users' activity list (status feed, for example).

The user has the option to pull this list down after the fact of them being authenticated and here is my code, thus far:

# User Model
  def gplus
    auth = authorizations.find_by_provider("gplus")
    client = Google::APIClient.new(application_name: "AppName", application_version: '1.0', authorization: nil)

    plus = client.discovered_api('plus', 'v1')

    result = client.execute(
      key: API["gplus"][Rails.env]["secret"],
      api_method: plus.people.get,
      parameters: { 'collection' => 'public', 'userId' => 'me'  }
    )

    return result.data
  end

Here is the problem I keep running into (from rails console)

    #<Google::APIClient::Schema::Plus::V1::Person:0x3fe649ed04bc 
DATA:{"error"=>{"errors"=>[{"domain"=>"usageLimits", "reason"=>"keyInvalid", "message"=>"Bad Request"}], "code"=>400, "message"=>"Bad Request"}}>

I am using the https://github.com/google/google-api-ruby-client... any reason why this won't work?

Was it helpful?

Solution

Code is close, but not quite there!

  1. You're getting the auth object, but not actually passing it to your client there (you're setting it to nil).
  2. You seem to be passing your client secret as the API key, which will cause problems. They API key is for a "simple API access" key from the API console - you don't need to pass anything if you're using an oAuth 2.0 token. If you'd like, you can pass a Server simple API key. This actually catches incorrectly using access tokens for a different project, so can be handy, but isn't required.
  3. You don't need to specify a collection argument for plus.people.get

Additionally, make sure that the Google+ API is enabled under Services in the API console: http://developers.google.com/+

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top