Google API Client Error: the caller does not have permission - google-api-client

I'm trying to use the Google API Client to gain access to a Google Doc. I get the following error:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://docs.googleapis.com/v1/documents/1Dc82X_w8UsyZnJe5JEh4E0wNdfbw-_nhVWXwgEJ4HVg?alt=json returned "The caller does not have permission". Details: "The caller does not have permission">
The error comes up in the file extract_text.py, which I got from here: https://developers.google.com/docs/api/samples/extract-text
Specifically, the error shows up at this line when it's obtaining the document's ID:
doc = docs_service.documents().get(documentId=documentID).execute()
The error states that my request has invalid authentication credentials (https://cloud.google.com/asset-inventory/docs/faq). I have made sure that I setup the OAuth correctly.

Related

Get error to call HandshakeException:unable to get local issuer certificate(handshake.cc:363))

I get this error when i call api with get and post Method using http or dio.
How can i resolve this error.
This is my api calling code and below is console showing error

Ruby gem facebook_ads exception_with_response: 400 Bad Request

I'm trying to query the Facebook Marketing API Insights using the facebook_ads Ruby gem. https://github.com/tophatter/facebook-ruby-ads-sdk
I created an app and have Editor permissions on the relevant pages for my company.
Next, I generated a user access token from this page after selecting ads_management permissions.
Next, I followed the instructions on this page to get a permanent page access token.
With the code below I get this error:
/var/lib/gems/2.3.0/gems/rest-client-/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:223:in exception_with_response': 400 Bad Request (RestClient::BadRequest)
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:103:inreturn!'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:809:in process_result'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:725:inblock in transmit'
from /usr/lib/ruby/2.3.0/net/http.rb:853:in start'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:intransmit'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in execute'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:inexecute'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient.rb:67:in get'
from /var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/base.rb:15:inget'
from /var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/ad_account.rb:10:in `all'
I have also tried this code with my temporary user access code but get the same result.
Here is my code
#!/usr/bin/ruby
require 'facebook_ads'
MY_PAGE_PERMANENT_ACCESS_CODE = 'my access code'
APP_SECRET = 'my app secret'
FacebookAds.access_token = MY_PAGE_PERMANENT_ACCESS_CODE
FacebookAds.app_secret = APP_SECRET
accounts = FacebookAds::AdAccount.all
It turns out that I was using the page permanent access token which was out of scope for the API call. I needed to use my temporary user access code.
E, [2019-01-19T00:08:49.366067 #19868] ERROR -- : GET /me/adaccounts
OAuthException / 100: (#100) Tried accessing nonexisting field
(adaccounts) on node type (Page) RestClient::BadRequest: 400 Bad
Request
In the pry console for the gem I ran this command to set the account variable:
pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID')
and I get this error:
E, [2019-01-19T00:12:24.760545 #20188] ERROR -- : GET /me/adaccounts
OAuthException / 2635: (#2635) You are calling a deprecated version of
the Ads API. Please update to the latest version: v3.2.
RestClient::BadRequest: 400 Bad Request
So, I ran this command:
pry(main)> FacebookAds.base_uri = 'https://graph.facebook.com/v3.2'
"https://graph.facebook.com/v3.2"
Then pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID') again.
Finally, I ran:
pry(main)> account.ad_insights
but the result is an empty array when I know this should not be blank. I'm going to skip the gem and use Ruby net/http to query the API directly.

"Access is denied due to invalid credentials" REST API error. How to solve?

I followed the documentation here: and here: Trying to integrate to a Personality Insights service via Android Java.
However, after the app runs, and using the correct username and password as mentioned in the guide... (the guide is not clear (2nd bullet point in "Before you begin") on which set of credentials to use - It says get the "service credentials" and credentials from the new service created - I tried with both and both fail with the same error below.)
Error:
12-11 01:49:56.201 29584-29632/? I/CredentialUtils: JNDI string lookups is not available. 12-11 01:49:56.269 29584-29632/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default 12-11 01:49:56.723 29584-29632/? D/OkHttp: --> POST https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 http/1.1 (1297-byte body) 12-11 01:49:56.803 29584-29632/? D/OkHttp: <-- 401 Not Authorized https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 (78ms, unknown-length body) 12-11 01:49:56.863 29584-29632/? E/WatsonService: POST https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13, status: 401, error: Not Authorized 12-11 01:49:56.865 29584-29632/? E/ERROR: Unauthorized: Access is denied due to invalid credentials
com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:492) at com.ibm.watson.developer_cloud.service.WatsonService$2.execute(WatsonService.java:254) at com.upen.personalityapp.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:105) at com.upen.personalityapp.MainActivity$RetrieveFeedTask.doInBackground(MainActivity.java:87) at android.os.AsyncTask$2.call(AsyncTask.java:306) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:244) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) 12-11 01:49:56.866 29584-29584/?
This is the code I am using; I am trying to pass a "text" input to the service.
service = new PersonalityInsights("2017-10-13");
service.setUsernameAndPassword("{myUsername}", "{myPassword}");
Profile profile = service.getProfile(text).execute();
System.out.println(profile);
return profile.toString();
I am using the com.ibm.watson.developer_cloud:personality-insights:3.8.0 dependency.
I tried connecting to the URL in the error (https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13 ) via a browser. It prompts for a username/password combo. I entered my details from my IBM Cloud Lite service but it throws the HTTP Error 405. Is this how it's supposed to work on the browser?
For someone in the future;
Instead of service.setUsernameAndPassword(username, password);, I tried service.setUsernameAndPassword("username", "password"); and it worked.

"unsupported URL" error given when accessing api gateway endpoint from swift

I have the following code that is trying to invoke and api gateway function called endsession in swift:
client.endsessionPost(body: pleasegod!).continue ({ (task:AWSTask) -> Any? in
if let error = task.error {
print("Error occurred: \(error)")
return nil
}
if let result = task.result {
print("IT WORKED")
// Do something with result
}
return nil
})
It runs and completes but task error occurs and the print statement of what the error is says:
Error occurred: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSUnderlyingError=0x618000056e60 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}, NSErrorFailingURLStringKey=(null)/endsession, NSErrorFailingURLKey=(null)/endsession, NSLocalizedDescription=unsupported URL}
It seems to be saying the endpoint url provided is bad. The endpoint url was just copied and pasted from the endpoint of the api gateway deployment so I am not sure why that would be an unsupported url.
The endpoint has a format like so:
https://kco37e2fsa.execute-api.us-west-1.amazonaws.com/TheStage
When I visit this endpoint in a browser I notice it says:
{"message":"Missing Authentication Token"}
Which is strange since both my api gateway resources have Authorization set to None and API Key set to not required on all their methods. Is this missing authentication token a clue as to why I am getting unsupported URL errors in swift when invoking the API??
The url https://xxxxxxxxxx.execute-api.us-west-1.amazonaws.com/TheStage will only work if you have a GET method configured on the root resource, and if that is deployed to a stage called TheStage. (No sure if the API Id and/or stage are real). A browser will send a GET request if you just navigate to the URL.
I would recommend a tool like Postman for testing API calls; you can configure parameters, body, HTTP method, auth, etc.

ACS/Facebook Integration - ACS40001: An error occurred while attempting to get an access token from Facebook

Getting the following error setting up ACS/Facebook integration:
HTTP Error Code: 502 Message: ACS40000: An error occurred while
processing a Facebook sign-in response. This may be caused by invalid
configuration of the Facebook application. Inner Message: ACS40001:
An error occurred while attempting to get an access token from
Facebook. Inner Message: ACS90005: Web exception Trace ID:
988ec1a7-e02b-4dcf-abab-51812745a121 Timestamp: 2011-07-12 19:59:51Z
I've verified that App ID, App Secret, Site URL and Site Domain have all been set.
For Site Url, we're using https://project.accesscontrol.windows.net
For Site Domain, we're using project.accesscontrol.windows.net
I'm using the following as a guideline:
http://blogs.objectsharp.com/cs/blogs/steve/archive/2011/04/21/windows-azure-access-control-services-federation-with-facebook.aspx?CommentPosted=true#commentmessage
http://www.leastprivilege.com/AccessControlServiceV2AndFacebookIntegration.aspx
Any ideas would be appreciated.
Just checked my (working) settings. Differences I see:
I did not enter a Site Domain over at Facebook
On the ACS side, I have "Application permissions" set to "email" (not sure if you have something entered there?)