I am getting com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials error while i am using the right credentials. I am doing like this..
Imports :
import com.ibm.watson.developer_cloud.visual_recognition.v2_beta.VisualRecognition;
import com.ibm.watson.developer_cloud.visual_recognition.v2_beta.model.VisualClassification;
Code :
service = new VisualRecognition(VisualRecognition.VERSION_DATE_2015_12_02);
service.setUsernameAndPassword("GXXXXxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
File image = new File("src/test/resources/visual_recognition/car.png");
VisualClassification result = service.classify(image).execute();
Dependencies :
compile 'com.ibm.watson.developer_cloud:java-sdk:3.0.0-RC1'
Where on Bluemix the Visual Recognition credentials are like this
{
"credentials": {
"url": "https://gateway.watsonplatform.net/visual-recognition-beta/api",
"password": "GXXXXxxxxxxx",
"username": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
Please help me to solve the issue. Thanks in advance!
This may be an error in your question, rather than an error in your code, however please double check that you pass to setUsernameAndPassword method the parameters in the correct order (username, password) as specified in the API Reference. Looking at your code I see
service.setUsernameAndPassword("GXXXXxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
that is (password, username). I've just tried using the correct order and it works fine for me.
Related
I'm trying to use the Google Cloud Translation API in my application but whenever I try to translate something it comes up with this missing valid API error.
I've done the quickstart steps and that didn't work.
I've tried the steps in the client library authentication and that hasn't worked either.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: herrsa1.bit.translator, PID: 16598
com.google.cloud.translate.TranslateException: The request is missing a valid API key.
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:61)
.. 18 more
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [{
"domain" : "global",
"message" : "The request is missing a valid API key.",
"reason" : "forbidden"
}],
"message" : "The request is missing a valid API key.",
"status" : "PERMISSION_DENIED"
}
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
... 4 more
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:130)
... 19 more
If you are using client library and you have already downloaded your service account json file, try doing this:
// Instantiates a client
const translate = new Translate({
projectId: 'your project id', //eg my-proj-0o0o0o0o'
keyFilename: 'path of your service acount json file' //eg my-proj-0fwewexyz.json
});
instead of this:
// Instantiates a client
const translate = new Translate({projectId});
This way you need only your the service acount json file and the specific API enabled
The error on API key means you didn't create or use the key properly. You need to do the following for the key to work:
Create a service account
Create a key for above service account
Download the key to a location, for example, a local path
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the key, refer to samples in Quickstart tutorial
I'd reccomend doing #1 & #2 in GCP Console, and handling #3 & #4 in Cloud Shell.
The key your using does not have the permission to use Translate APIs.
To fix this :
Go to Google Cloud Platform console
Chose your project from the drop down menu in the top bar
Go to API & Services > Library
Search for Cloud Translation API and click on it
Enable it
Go to API & Services > Credentials
Select the key you are using in your Android App
From the menu called Restrict key, choose Cloud Translation API
Save your edit
Now the APIs will work properly.
I also tried to execute this sample program.
I followed the same instruction. But when I executing I got same error(The request is missing a valid API key).
I changed a line in the sample program.
Instead of
Translate translate = TranslateOptions.getDefaultInstance().getService();
I added
Translate translate = TranslateOptions
.newBuilder()
.setCredentials(
ServiceAccountCredentials
.fromStream(new FileInputStream(
"YourCredentialFilePath.json")))
.build().getService();
Now it is working.
Sample code after fix.
// Imports the Google Cloud client library
import java.io.FileInputStream;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.Translate.TranslateOption;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
public class QuickstartSample {
public static void main(String... args) throws Exception {
//Instantiates a client
//Removed next line
//Translate translate = TranslateOptions.getDefaultInstance().getService();
//Added this line
Translate translate = TranslateOptions
.newBuilder()
.setCredentials(
ServiceAccountCredentials
.fromStream(new FileInputStream(
"YourCredentialFilePath.json")))
.build().getService();
//The text to translate
String text = "Hello, world!";
//Translates some text into Russian
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
}
I'm trying to integrate the PayPal Here swipers into a Xamarin Android app. Everything is fine until I try and give my credentials to the SDK. Specifically, the line containing the call to PayPalHereSDK.SetCredentials
public void InitializeSdk( Context context, string serverName, string accessToken, string refreshUrl, string expires, IPayPalHereSdkWrapperCallback listener ) {
PayPalHereSDK.Init( context, serverName );
PayPalHereSDK.RegisterAuthenticationListener( this );
PayPalHereSDK.CardReaderManager.RegisterCardReaderConnectionListener( this );
if ( !string.IsNullOrEmpty( accessToken ) ) {
var credentials = new OAuthCredentials( accessToken, refreshUrl, expires );
PayPalHereSDK.SetCredentials( credentials, new SetAccessTokenResponseHandler( listener ) );
}
}
My SetAccessTokenResponseHandler class implements the Com.PayPal.Merchant.Sdk.Domain.IDefaultResponseHandler interface. As described above, the OnError function is called when call the PayPalHereSDK.SetCredentials function. I'm given the error code "BadConfiguration" and the message "Cannot proceed with this merchant account. ready"
I've searched Google high and low and, I believe, scoured SO pretty thoroughly. I can't seem to overcome the error, so I'm asking for help!
I think the paypal email is not verified properly. Please go through the merchant onboarding guide document to get more details regarding making the merchant eligible.
https://github.com/paypal/paypal-here-sdk-android-distribution/blob/master/docs/Merchant%20Onboarding%20Guide.pdf
Hope this helps. Cheers.
I'm not sure what exactly the issue was, but I ended up deleting the Sandbox App in my PayPal dev portal and creating a new one. Everything works now. head scratch
I resorted to this because, while trying to follow Sundar's suggestion, I started getting an "invalid scope" error. I had received them before and KNEW I had it fixed ( and no code had changed ). When I deleted/recreated the app, that error went away. Frustrating, but that's what worked!
I'm beginning to use CloudCode but I can't find my application after authentication.
Once I enter my email account and pass I get the following:
Email:
Pass:
1: results
Select an App:
From this step nothing works (Ex. parse deploy) and I get the error msg "Unknown application _default"
I'm using the latest parse-windows.2.0.11.exe, PowerShell on Win8.1
Should CloudCode be activate on the project in order to use it? if so, how is this done?
===UPDATE===
It turns out the global.json was created wrong (bug?)
{
"applications": {
"results": {
"applicationId": {
"appName": "AppName1",
"applicationId": "zzz",
"masterKey": "zzz"
},
"masterKey": {
"appName": "AppName2",
"applicationId": "xxx",
"masterKey": "xxx"
}
}
}
}
I've manually fixed it using this thread link
Hope this will help others..
=== END UPDATE===
Please advise.
Thanks,
Liran
My experience is with Android over Linux, but from what I see the base is the same - in Linux you create a folder for your CloudCode that you reference for deployments, so when you deploy you do that from inside that folder, read carefully through This Parse Tutorial - seems pretty similar.
So I'm on a Mac with Eclipse and I'm trying to add the new relic plugin. I've already followed the instructions up to import.
import com.newrelic.agent.android.NewRelic;
But now when I try to add the code:
NewRelic.withApplicationToken(mycode).start(this.getApplication());
where mycode is just the id as String given to me by new relic. I get an error that says:
Syntax error on token "withApplicationToken", = expected after this token
Any ideas?
I think there might be some error in where this line was added or how the token was formatted.
Here's the exact formatting for this code, in its context:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NewRelic.withApplicationToken(
"AA9b032a80e2658208a0180ec09ff1f059badb7756"
).start(this.getApplication());
setContentView(R.layout.lookup);
That's just a demo token, I've altered some characters in my token so that you won't start sending to my dashboard :)
If that doesn't fix it, I would send a complete code snippet to New Relic in a support ticket, either under 'help' in your dashboard or at support#newrelic.com.
If you do open a ticket and there's a general solution, I'll come back here and post the right steps for other users.
This line looks fine. Is there a missing semicolon or something in the previous line? Can you verify that?
seriously going insane here....
I'm trying to get the phonegap facebook plugin for android to work, but it's really driving me up the wall (no pun intented).
I am using the code from https://github.com/irnc/phonegap-plugin-facebook-connect/tree/oauth-2.0+irnc, at least I think I am.
I appear to have two problems:
the following callback in the login (from pg-plugin-fb-connect) gives an error because "FB.Auth.setAuthResponse(response.authResponse, response.status);" cannot be found. Am I using an incorrect facebook sdk? Apparently no, see edit below
PhoneGap.exec(function (response) {
console.log('PG.FB.login.success: ' + JSON.stringify(response) + ', store into localStorage ...');
localStorage.setItem(key, JSON.stringify(response));
FB.Auth.setAuthResponse(response.authResponse, response.status);
if (cb) {
cb(response);
}
}, null, service, 'login', ['publish_stream', 'read_stream']);
},
When I comment the FB.Auth.setAuthResponse(response.authResponse, response.status); statement, my login returns successfull! I get an authresponse with an accesstoken and status set to connected. When I try to execute the following code (on success callback)
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
console.log(JSON.stringify(response.error, null, 4));
alert('We are very sorry, but somthing went wrong');
} else {
alert('Message was successfully posted to your wall!');
}
});
it gives me an oauthexception message: "An active access token must be used to query information about the current user."
I authenticated with 'read_stream, publish_stream' permissions.
These two are probably related, but I can't find anything about the setAuthReponse call in the facebook api.
EDIT help is apparently not on it's way, but i've continued my quest to get this to work.
The facebook js sdk I got from the github repo's are all using the 'old' auth methods. I've downloaded the new facebook js sdk and FB.Auth.setAuthResponse is there. I copied the code to my existing js sdk and changed all calls to setSession to setAuthRepsonse. Everything is working fine, except that the access token doesn't appear to be posted when I make above FB.api calls. After these changes, the error remains exactly the same!
Oh yeah, I also changed the check in the login callback to check for authResponse instead of session (it's in the example).
Help is more than welcome,
rinze
I think I fixed this. Basically the ConnectPlugin.java is still returning a "session" response object instead of the "authResponse" that the new SDK expects.
See https://github.com/odbol/phonegap-plugin-facebook-connect/commit/0ef84e29603338930ff82fc6d6ef8525b668077d for details.