Android : Get the token using GoogleAuthUtils. Invalid Client ID - android

I am trying to get authenticated token from GoogleAuthUtils. Keep having Invalid Client ID message like this.
GLS error: INVALID_CLIENT_ID myEmailAddress audience:server:client_id:NUM.apps.googleusercontent.com:api_scope:https://picasaweb.google.com/data
The NUM = xxxxxxx-yyyyyyyy.apps.googleusercontent.com where I used xxxxxxx part. I even tried using the y parts or both but none works. Am I missing something here?
String token = GoogleAuthUtil.getToken(PicassaFragment.this.getActivity(),
Plus.AccountApi.getAccountName(client),
scope
);
This is the code i received the error message.

Related

Android AWS Amplify.Auth.signUp() / AWSMobileClient.getInstance().signUp() have same errorCodes for error cases

How to distinguish error cases for signUp process?
Only one case (password's length is less then 6) is different to others (both for Amplify and AWSMobileClient solutions):
user password less then 6 symbols:
{InvalidParameterException#11448} "com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException: 1 validation error detected: Value at 'password' failed to satisfy constraint: Member must have length greater than or equal to 6 (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: InvalidParameterException; Request ID: 1f65fd14-0d11-483a-9fc2-1dfc9854127e)"
user password satisfy above demand, but does't not contain uppercase characters:
{InvalidPasswordException#11481} "com.amazonaws.services.cognitoidentityprovider.model.InvalidPasswordException: Password did not conform with policy: Password must have uppercase characters (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: InvalidPasswordException; Request ID: 2d046ca6-d462-4165-bf27-5575ce806b22)"
user password satisfy above two demands, but does't not contain numeric characters:
{InvalidPasswordException#11525} "com.amazonaws.services.cognitoidentityprovider.model.InvalidPasswordException: Password did not conform with policy: Password must have numeric characters (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: InvalidPasswordException; Request ID: b657ff9e-520a-429a-982f-29c1695ca1bd)"
the same errorCode for case when password doesn't contain special symbols like !##$% etc.
But for Amplify.Auth.confirmSignUp() / AWSMobileClient.getInstance().confirmSignUp() I have different errorCodes:
val errorMessage = when (exAws.errorCode) {
"AliasExistsException" ->
mess = 'An account with the email already exists.'
"CodeMismatchException" ->
mess = 'Invalid verification code provided, please try again.'
. . . . .
}
Yes, currently Amplify Auth and AWSMobileClient use errorCode of exactly the same name but different types. For Amplify Auth, the error type is Amplify.AuthException.
Could you please specify your question with more details?

OTP Verification unknown keyword error in Twilio with Rails

want to send android app hash along with the otp with the help of twillio but not getting proper tutorails in rails. i tried in this way
require 'twilio-ruby'
#client = Twilio::REST::Client.new("XXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXX")
verification = #client.verify.services('VXXXXXXXXXXXXXXXXX').verifications.create(app_hash: "HXXXXXXX", to: '+91XXXXXXXXX', channel: 'sms')
But getting againg and again error
unknown keyword: app_hash
I followed this tutorial https://www.twilio.com/docs/verify/api/verification
Your app's hash string is the first 11 characters of the base64-encoded hash.
Try to pass 11 characters: Ex: 'He42w354ol9'.
verification = #client.verify
.services('VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.verifications
.create(to: '+15017122661', channel:'sms', app_hash:'He42w354ol9')
Source: https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string
The Twilio Ruby API excerpt goes like:
#client = Twilio::REST::Client.new(account_sid, auth_token)
verification = #client.verify
.services('VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.verifications
.create(to: '+15017122661', channel: 'sms')
I don't see any app_hash parameter, where did you get that from? Try removing it and see what's going on.

Events subscription via webhooks using MS graph Android SDK

I am implementing events subscription using MS graph android SDK. Below is the code.
IGraphServiceClient mGraphServiceClient = GraphServiceClientManager.getInstance(context).getGraphServiceClient();
mGraphServiceClient.getSubscriptions().buildRequest().post(getSubscription(email, expirationDate), subscriptionICallback);
private Subscription getSubscription(String email, Calendar expirationDate) {
Subscription subscription = new Subscription();
subscription.expirationDateTime = expirationDate;
subscription.notificationUrl = "<Webhook link>";
subscription.changeType = "created,updated";
subscription.resource = "me/events";
subscription.clientState = Base64.encodeToString(email.getBytes(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
return subscription;
}
The request body generated through this always throws the error:
Error during http request Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
E/DefaultHttpProvider[sendRequestInternal] - 286: [...]
E/DefaultHttpProvider[sendRequestInternal] - 286: [Some information was truncated for brevity, enable debug logging for more details]
E/DefaultHttpProvider[sendRequestInternal] - 286: Throwable detail:
com.microsoft.graph.http.GraphServiceException: Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
at com.microsoft.graph.http.DefaultHttpProvider.handleErrorResponse(DefaultHttpProvider.java:310)
at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:246)
at com.microsoft.graph.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:47)
at com.microsoft.graph.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
E/agenday.com.pgi.agenday.ui.BaseActivity: create Subscription exceptionError code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"#odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
but the same request body is working fine in graph explorer,
I have tried many things now but unable to resolve it. How can I get this to work for subscriptions in Android, I can't find any resources for this online.
The issue was due to the BaseSubscription model in Microsoft graph SDK where it is setting "#odata.type":"microsoft.graph.subscription" by default and subscription api is not supporting this in request body and throwing the error: 400
So I resolved it by explicitly making "#odata.type" to null in the subscription model and pass it to post request which worked successfully for me.
Thanks!

Can I open my email thread in Gmail App If I have id or threadId?

I am using gmail APIs in my android app and I am able to get id and threadId.So is there any way I can populate gmail using these ids.
Once you have the messageId representing the message you want, you can simply use the Users.messages: get-operation to get the email. You could either do the request manually
GET https://www.googleapis.com/gmail/v1/users/me/messages/<MESSAGE_ID>
or with the help of a library:
Message message = service.users().messages().get('me', messageId).execute();
If you want to get all the mails in the thread, it is just as easy to do that also.
Look at code examples and explore the API in the links I provided.
You can get the raw message in following way This is in python but in Java it would be similar. I hope I answered what you are looking for.
def GetMimeMessage(service, user_id, msg_id):
"""Get a Message and use it to create a MIME Message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
msg_id: The ID of the Message required.
Returns:
A MIME Message, consisting of data from Message. """
try:
message = service.users().messages().get(userId=user_id, id=msg_id, format = 'raw').execute()
print 'Message snippet: %s' % message['snippet']
print 'keys ', message.keys()
msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
mime_msg = email.message_from_string(msg_str)
return mime_msg
except errors.HttpError, error:
print 'An error occurred: %s' % error
for i in range(0,len(th['messages'])):
print 'snippent --- ', th['messages'][i]['snippet']
id = th['messages'][i]['id']
print 'id---', id
msg = GetMimeMessage(service, 'me', id )
pay = msg.get_payload()
pay1 = pay[0]
print 'msg --- ', pay1.get_payload()

Post push notification to C2DM (android) using Django

I found how to send push notification to Android device using Django here (here is the code).
So adopted that and my code looks like this:
def sendAndroidPushNotification(registration_id, collapse_key, a, b) :
try:
auth = getNewAndroidAuthorizationToken() # this works I'm fetching new token so this is up to date (its length is 267 characters)
push_request = urllib2.Request("https://android.apis.google.com/c2dm/send")
data = urllib.urlencode({'data.testA' : a,
'data.testB' : b,
'collapse_key' : collapse_key,
'registration_id': registration_id
})
push_request.add_data( data )
push_request.add_header('Authorization', 'GoogleLogin auth=' + auth)
push_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
push_request.add_header('Content-Length', len(data))
urllib2.build_opener().open(push_request)
except urllib2.HTTPError as e:
print 'got exception during push notification'
print 'Reason: "{0}" code: {1}'.format(e.reason, e.code)
pass
this give me error: "Reason: "Unauthorized" code: 401" (at some point it was 403). Version which uses httplib.HTTPSConnection instead of urllib2.Request has same problem.
It looks almost the same as code shown here so I'm totally confused. What I'm doing wrong?
Edit:
Just in case, here is how I fetch authorization token (it looks like that it works fine), maybe my parsing is wrong:
def getNewAndroidAuthorizationToken() :
request = urllib2.Request("https://www.google.com/accounts/ClientLogin")
data = urllib.urlencode({'accountType' : 'HOSTED_OR_GOOGLE',
'Email' : 'someaccount#gmail.com',
'Passwd' : 'asdjsdfa',
'service' : 'ac2dm',
'source' : 'com.mycompany.mypackage',})
request.add_data(data)
content = urllib2.build_opener().open(request)
lines = content.readlines()
for line in lines :
if line.find("Auth=")==0 :
return line[5:]
return
C2DM is deprecated. Developers are encouraged to switch to GCM, C2DM will be supported for a short time. Simple API instead of ClientLogin and oAuth2 which are not supported.
http://developer.android.com/guide/google/gcm/index.html

Categories

Resources