"Invalid credentials" Google plus with request /plus/v1/people/me - java

I'm doing sign in with Google+ and always I received the token correctly but when I want to make a request with this token to "https://www.googleapis.com/plus/v1/people/me" via curl. I always get the same error.
Code android to make login:
// Scope to get the token with the user information
public static final String SCOPE_GOOGLE_USER_INFORMATION = "https://www.googleapis.com/auth/userinfo.profile";
public static final String SCOPE_GOOGLE_PLUS_ME = "https://www.googleapis.com/auth/plus.me";
public static final String SCOPE_GOOGLE_PLUS_LOGIN = "https://www.googleapis.com/auth/plus.login";
public static final String SCOPE_GOOGLE_PLUS_EMAIL = "https://www.googleapis.com/auth/userinfo.email";
public static final String SCOPE = "oauth2:" + SCOPE_GOOGLE_USER_INFORMATION + " " + SCOPE_GOOGLE_PLUS_ME + " " + SCOPE_GOOGLE_PLUS_LOGIN + " " + SCOPE_GOOGLE_PLUS_EMAIL;
String token = GoogleAuthUtil.getToken(activity, userEmail, SCOPE);
And then I make the curl request:
curl -H "Authorization: Bearer TOKEN" https://www.googleapis.com/plus/v1/people/me?key={KEY}
Always I received the same error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
but If I do the same process via https://developers.google.com/oauthplayground/ works

You key and access token have to be from the same project. You can check the project number of the access token by plugging it into to: https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=
Remove the plus.me scope as well, that is not needed. The email and profile scopes can be replaced with the strings "email" and "profile" respectively (no https://wwww.googleapis.com etc.). plus.login is reasonable, but if you're just getting basic profile, you don't need it - the profile scope will give you that from the plus API.

Related

Iterate over Laravel validation errors object in java

I have an android app that uses laravel as backend. I validate user inputs in laravel using Validator facades.
$validator = Validator::make($inputs, $rules);
if ($validator->fails()) {
return response(['errors' => $validator->errors()], 401);
}
The response is an json object that could have different elements.
{
"errors": {
"username": [
"The username has already been taken.",
"The username format is invalid."
],
"email": [
"The email has already been taken."
]
}
}
or
{
"errors": {
"password": [
"The password must have at least 8 characters."
]
}
}
I get the JSONObject in the android app using java.
JSONObject errors = jsonObject.getJSONObject("errors");
My question is that how can I iterate over the errors object to show the errors?

LinkedIn UGC Post Method

I am trying to post a text on LinkedIn using UGC through Postman.
Here is my request body:
{
"author": "urn:li:person:{uid of my account}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
Note: uid of my account is fetched through - https://api.linkedin.com/v2/me
The response I am getting is:
{
"message": "ERROR :: /author :: \"urn:li:person:oQRNppEnm\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n",
"status": 422
}
Can anyone please help out here?
I had such a mistake. I used wrong value from https://api.linkedin.com/v2/me request answer. You need to add id in your request query if you haven't already,
for example
https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)
also you need to use value from id field of JSON answer:
{"id\":\"XyyyyXXXXX\"}
It will be some kind of value with numbers and letters, not just numbers.

400 Error even if email exists in firebase

I am trying user authentication with firebase in java using spring framework. When ever I try to authenticate a user using the provided emailId and password I am getting a 400 Error, but the emailId does exist in the fireBase authentication as well as in the firebase realtime database page. I am also able to retrieve data using uuid which is available in fireBase authentication web page.
My code:
String googleAuthUrl =
env.getProperty("google.auth.identity.toolkit.url") +
env.getProperty("google.auth.identity.toolkit.key");
Client client = Client.create();
WebResource webResource = client.resource(googleAuthUrl);
ClientResponse response = webResource.accept("application/json").type("application/json")
.post(ClientResponse.class, inputJson);
Integer responseCode = response.getStatus();
String responseBody = response.getEntity(String.class);
logger.info("Google response : {}", responseBody);
// ...
My input :
{
"email": "abc#gmail.com",
"password":"test123"
}
Exception encountered:
Google response : {
"error": {
"code": 400,
"message": "EMAIL_NOT_FOUND",
"errors": [
{
"message": "EMAIL_NOT_FOUND",
"domain": "global",
"reason": "invalid"
}
]
}
}
Can anyone explain the reason for this exception and how to overcome the problem ! Instead of making a REST call is there an SDK available for user authentication ?
I just had a similar problem with same library but in flutter.
The problem was that I was sending the email with a white space at the end...
So, I don't know if you solved it but a trim() function can solved it, if is the case sure

How to update description in Jira through rest api with json

Below is the JSON data which contains rich text/wiki text. I want to pass this data to to one of the issues in Jira through REST API. Here Java is the technology, I am using.
{"update":{"summary": [{"set": "CRF-397 – For Virgin Mobile, alert must be sent via email when Tier Mismatch exception is encountered."}]},"fields":{"description":{"set":"*Clients Impacted** Virgin Mobile *Background Information*<br>All UK schemes are experiencing at different levels some issues of:* Customers being billed on the wrong premium* Excess Fees paid at point of claim do not correspond to what has been communicated to the customer at the point of sale.* Welcome packs not being issued due to a mismatch *CRF Scope*<br>The scope of this project consists of identifying whenever a new device is communicated to Asurion by a client system and ensuring the data in each of those instances is validated to confirm that the device premium and excess fees are correctly aligned.*User Story Scope*<br>While doing enrollment if any record goes into exception due to Tier is match we have to send consolidated list of such records via email so that Asurion Team can communicate with Virgin Mobile to resolve the Tier Mismatch issues.*Requirement** An email alert must be sent when Tier Mismatch exception is encountered.* Flag based development must be done for triggering an email.* Email must be sent to Client Service, SCM and BI teams* Recipient email IDs must be configurable.* Exception list must contain below records:- * The list of devices for which there was an exception * The Feature Code sent by Virgin Mobile * The feature code configured in Client Convention for the given device*"}}}
Above JSON I am storing in jiraUpdateFromBuilder.
I am calling PUT method to update description in Jira, as below.
String _jiraUrl = applicationProperties.get(Constants.JIRAURL)
+ "/rest/api/2/issue/" + reference;
String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
int statusCode = invokePutMethod(auth, _jiraUrl.trim(),
jiraUpdateFromBuilder.toString().trim());
public static int invokePutMethod(String auth, String url, String data) {
int statusCode = 0;
try {
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.header("Authorization", "Basic " + auth)
.type("application/json").accept("application/json")
.put(ClientResponse.class, data);
statusCode = response.getStatus();
return statusCode;
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
}
return statusCode;
}
Doing so, I am unable to update description of issue in Jira, through any REST API, because here getting status other than 201. And the same problem is with all the field of an Issue in JIRA which contains rich text. Kindly let me know if JRJC can help else if I need to change in JSON or any other approach.
Your json looks like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": {
"set": "..."
}
}
}
But the "fields" part does not require to use the 'set' keyword, so it should be something like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": "..."
}
}
If you check the documentation for the PUT /issue REST resource, you'll see that it mentions this:
Specifying a "field_id": field_value in the "fields" is a shorthand for a "set" operation in the "update" section.
Field should appear either in "fields" or "update", not in both.
Also, you've mentioned that your response status code was 400, which means it's a bad request. The response body will probably contain more detail about what is wrong, so it's best to log that as well.
Regarding this error:
Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream#20e841d2; line: 1, column: 187]
Your description value contains newlines, but it's not allowed to use those in a json string directly. You'll have to escape those. See this post for an example.
The Jira documentations and these answers seem to be outdated. With API version 3 of Jira. (API docs to edit issue)
Updating the description of an Issue in Jira:
HTTP Method: PUT
HTTP URL: https://cognitedata.atlassian.net/rest/api/3/issue/{issueIdOrKey}
Request Body:
{
"fields": {
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "add your description here"
}
]
}
]
}
}
}
If you use a different request body, you will get the following error:
{
"errorMessages": [],
"errors": {
"description": "Operation value must be an Atlassian Document (see the Atlassian Document Format)"
}
}

Appengine endpoint interprits List<Long> argument incorrectly

I have a GAE endpoint method which accepts a List<Long> argument.
#ApiMethod(name = "getBills")
public List<EndpointBill> getBills(#Named("emailAddress") String emailAddress, #Named("billIds") List<Long> billIds) {
}
I call above endpoint method from an android app like below (with help of generated client lib).
List<Long> billsToFetch = new ArrayList<>();
//Populate billsToFetch
EndpointBillCollection endpointBillCollection = myEndpoint.getBills("test#test.com", billsToFetch).execute();
But, endpoint throws an exception if billsToFetch list contains more than one element.
{
"code": 400,
"errors": [
{
"domain": "global",
"location": "billIds[0]",
"locationType": "parameter",
"message": "Invalid long value: '1,2'.",
"reason": "invalidParameter"
}
],
"message": "Invalid long value: '1,2'."
}
The error is Invalid long value: '1,2'.. As I observed, 1,2 value above is the bill IDs concatanated with a , character (billsToFetch contains 1 and 2. If billsToFetch contained 5 and 6, error message becomes Invalid long value: '5,6'.).
How should I fix this? Or, doesn't endpoints support List<Long> argument?

Categories

Resources