Vijikumar M
Vijikumar M

Reputation: 3764

Access Not Configured error while posting a message to google plus

I am using google-api-client gem to post message to google plus when a user logs in my application with his google plus credentials.

Below is my code.

 require 'google/api_client'
 require 'google/api_client/client_secrets'
 require 'google/api_client/auth/installed_app'
 keypath = Rails.root.join('config','poo-02a507f45ab4.p12').to_s
 key = Google::APIClient::KeyUtils.load_from_pkcs12(keypath, 'notasecret')


 client = Google::APIClient.new(
  :application_name => 'my app',
  :application_version => '1.0.0'
  )
urlshortener = client.discovered_api('urlshortener', 'v1')
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/prediction','https://www.googleapis.com/auth/plus.stream.write','https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/urlshortener','https://www.googleapis.com/auth/plus.circles.write'],
 :issuer => '[email protected]',
 :signing_key => key)
client.authorization.fetch_access_token!

 batch = Google::APIClient::BatchRequest.new do |result|
   puts result.data
end
batch.add(:api_method => urlshortener.url.insert,:body_object => { 'longUrl' => 'https://www.facebook.co.in' })
client.execute(batch)

While trying this code its giving below error.

{\n \"domain\": \"usageLimits\",\n \"reason\": \"accessNotConfigured\",\n \"message\": \"Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.\",\n

I have enabled google + API and contacts API in developers console.

Please help me to solve this problem.

Upvotes: 1

Views: 153

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116968

The problem you are having is that you are using a service account.

The Google OAuth 2.0 system supports server-to-server interactions such as those between a web application and a Google service. This scenario is called a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren't directly involved.

If you want to post on behalf of a user you will need to be using Oauth2, then you will be able to authenticate the user.

Update:

So that you are aware it is not possible to post to a users Google+ time line. the best you can do is post something called moments which isn't really the same thing. An issue request was made for this in 2011 I think they have yet to add this feature.

Upvotes: 1

Related Questions