How To Receive Urban Airship Apid From Android Device_Token?

I receive device_token with Corona (in the same way as in the sample"GooglePushNotifications" example). How can I convert it to Urban Airship’s APID? 

 

I tried this code (from one of the posts here):

[lua]

 

 

local function registerUrbanDevice(deviceToken)

    local secretString = mime.b64(APPKEY … “:” … APPLICATIONSECRET)

    headers = {}

    headers[“Authorization”] = "Basic " … secretString

    headers[“Content-Type”] = “application/json”

    body = “”

    local params = {}

    params.headers = headers

    params.body = body

    network.request( “https://go.urbanairship.com/api/device_tokens/” … deviceToken ,  “PUT”, urbanNetworkListener,  params)

end

 

[/lua]

 

 

But I receive the Urban Airship response “bad request”.

local function registerUrbanDevice(deviceToken) local secretString = mime.b64(APPKEY .. ":" .. APPLICATIONSECRET) headers = {} headers["Authorization"] = "Basic " .. secretString body = "" local params = {} params.headers = headers params.body = body network.request( "https://go.urbanairship.com/api/device\_tokens/" .. deviceToken, "PUT", function(event) if (event.isError) then --You have an error else --everything is fine end end, params) end

 

:slight_smile:

 

@cbishop thanks, i tried to copy your  function, but i still have the same issue: 

i receive event.response = Can’t understand that content-type!

when i add the  s[“Content-Type”] = “application/json”, i receive event.response = Bad Request

local function registerUrbanDevice(deviceToken) local secretString = mime.b64(APPKEY .. ":" .. APPLICATIONSECRET) headers = {} headers["Authorization"] = "Basic " .. secretString body = "" local params = {} params.headers = headers params.body = body network.request( "https://go.urbanairship.com/api/device\_tokens/" .. deviceToken, "PUT", function(event) if (event.isError) then --You have an error else --everything is fine end end, params) end

 

:slight_smile:

 

@cbishop thanks, i tried to copy your  function, but i still have the same issue: 

i receive event.response = Can’t understand that content-type!

when i add the  s[“Content-Type”] = “application/json”, i receive event.response = Bad Request

Tatiana did you ever resolve this? I’m getting Bad Request and basically using same code as you.

Edit: made a new thread here: http://forums.coronalabs.com/topic/35754-urban-airship-and-android/

Add this instead:

headers["Content-Type"] = "application/x-www-form-urlencoded"

chevol: Do you have Urban Airship device ID registration working for Android  in Corona?

@jonjonsson I received answer from Urban Airship that we can’t generate Urban Android token w/o native Urban SDK (it is possible to generate the token only for iPhone). Maybe you can try with Corona Enterprise to use Urban’s SDK for Android token generation ( I can’t say something detailed about, I am only Pro Corona user).

OK that’s final then, I think chevol might be talking about iOS above.

I’m a pro subscriber as well and I don’t have native Android programming experience as well. So I don’t think I’m the right guy for the job :slight_smile:

Yup, I’m working on iOS side of things. Eventually I need to work on Android too but for now just iOS.

jonjonsson - great catch with the Content-Type issue - finally, Urban Airship is working!!!

Hey, that was me lol. Anyways, crussell are you using it on Android or iPhone? 

Tatiana did you ever resolve this? I’m getting Bad Request and basically using same code as you.

Edit: made a new thread here: http://forums.coronalabs.com/topic/35754-urban-airship-and-android/

Add this instead:

headers["Content-Type"] = "application/x-www-form-urlencoded"

chevol: Do you have Urban Airship device ID registration working for Android  in Corona?

@jonjonsson I received answer from Urban Airship that we can’t generate Urban Android token w/o native Urban SDK (it is possible to generate the token only for iPhone). Maybe you can try with Corona Enterprise to use Urban’s SDK for Android token generation ( I can’t say something detailed about, I am only Pro Corona user).

OK that’s final then, I think chevol might be talking about iOS above.

I’m a pro subscriber as well and I don’t have native Android programming experience as well. So I don’t think I’m the right guy for the job :slight_smile:

Yup, I’m working on iOS side of things. Eventually I need to work on Android too but for now just iOS.

jonjonsson - great catch with the Content-Type issue - finally, Urban Airship is working!!!