OTP Verification unknown keyword error in Twilio with Rails - android

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.

Related

Set paper size A4 while printing from google cloud print API

I have integrated Google cloud printing API in android application. I am printing image from GCP. Everything is working fine. I want to set paper size using API. Is that feasible?
Currently i am sending following data :
**URL :**...cloudprint/submit
**Param :**
printerid
file
title
contentType
As per google document, we can use ticket param for that. not sure what to send in this key.
Any help appreciated.
We need to pass the A4 specifications to the G.C.Printer.
You need to pass ticket in the path parameter along with printerid, file, title, contentType and should look like this:
ticket : {"version":"1.0","print":{"media_size":{"width_microns":210000,"height_microns":297000,"is_continuous_feed":false,"vendor_id":"ISO_A4"}}}
(^above are the specs of A4 media size)
Your params should look like this:
printerid : <printerid>
content: <content>
title : <title>
contentType: <contentType>
ticket : {"version":"1.0","print":{"media_size":{"width_microns":210000,"height_microns":297000,"is_continuous_feed":false,"vendor_id":"ISO_A4"}}}
Also, this works perfectly for GCP version 2.0
Ticket params is basically the settings we send to G.C.Printer and by default, it sends media type as "NA_LETTER". We can override the default settings by sending the ticket parameter to trigger the print.
GCP parses the ticket and uses the key value accordingly. If any key is wrong, it throws "unable to parse ticket" error.

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()

How to Authenticate with Alexa Voice Service from Android?

I am trying to connect to Alexa Voice Service from an Android app following the directions on this page: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app
Bundle options = new Bundle();
String scope_data = "{\"alexa:all\":{\"productID\":\"" + PRODUCT_ID +
                    "\", \"productInstanceAttributes\": {\"deviceSerialNumber\":\"" + PRODUCT_DSN + "\"}}}";
options.putString(AuthzConstants.BUNDLE_KEY.SCOPE_DATA.val, scope_data);
options.putBoolean(AuthzConstants.BUNDLE_KEY.GET_AUTH_CODE.val, true);
options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE.val, CODE_CHALLENGE);
options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE_METHOD.val, "S256");
mAuthManager.authorize(APP_SCOPES, options, new AuthorizeListener());
First, I don't know what APP_SCOPES should be. I set it to:
protected static final String[] APP_SCOPE = new String[]{"profile", "postal_code"};
but I get an error from the server
AuthError cat= INTERNAL type=ERROR_SERVER_REPSONSE - com.amazon.identity.auth.device.AuthError: Error=invalid_scope error_description=An unknown scope was requested
What am I doing wrong and how can I do this right?
The APP_SCOPE is : "alexa:all"
The PRODUCT_DSN can be anything you want, "1234" as per suggestion from Joshua Frank (https://forums.developer.amazon.com/forums/message.jspa?messageID=18973#18973)
The PRODUCT_ID is the ID in the AVS Developper Portal (https://developer.amazon.com/edw/home.html#/avs/list)
The CODE_CHALLENGE the Client Secret in the Security Profile of your application (should be already hashed in S256)
The problem is not with the APP_SCOPES variable, it is actually with the PRODUCT_ID, PRODUCT_DSN variables passed in the scope data.
I faced this exact same issue and have raised a query in amazon developers forum on what needs to be passed in those variables - Alexa authentication issue using beta SDK
Once the PRODUCT_ID, PRODUCT_DSN & CODE_CHALLENGE variables are determined then the authentication should be pretty much straight forward.
The APP_SCOPE should be "alexa:all"

Android : Get the token using GoogleAuthUtils. Invalid Client ID

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.

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