Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unity OAuth for an android app

ANSWERED

Hey,

 

So I'm trying to get started with making a game that involves the fitbit but after reading around about OAuth it seems that no one has a conclusive answer on how to do it nicely with Unity. Wondering if anyone does know a good way to get it going (whether that is actually using OAuth.io or if I can do it with the .net library version)

 

I want to tackle this first so I don't spend time making the game to find out I can't get it to integrate properly.

So if anyone has a place I can start at that would be stellar 🙂

 

Best Answer
1 BEST ANSWER

Accepted Solutions

The link you put is exactly what I was needing to get the api to recognize the application at least. 

 

Guess I just gotta figure out how to get the callback now cause it doesn't seem to be actually redirecting anywhere 😞

View best answer in original post

Best Answer
0 Votes
6 REPLIES 6

Hey, well I finally got something going..I think

 

After fiddling with the Debug tool a bit I'm just a bit confused as to what I'm supposed to be checking compared to what I generate in my program..

 

The debug tool is giving a pretty strange result such as 

POST&https%3A%2F%2Fapi.fitbit.com%2Foauth%2Frequest_token&oauth_consumer_key%3

Should my program be generating the POST and the % as well or would the 

https://api.fitbit.com/oauth/request_token?oauth_consumer_key=

be fine?

I don't think I'm too far off of getting it working but just a slight big confused on some of the aspects (never done web programming before)

 

The response I get when I try to follow the url I generate is 

{"errors":[{"errorType":"oauth","fieldName":"n/a","message":"No Authorization header provided in the request. Each call to Fitbit API should be OAuth signed"}],"success":false}

 Also, first time with OAuth, not sure if it's safe to post the url I generate/debug url  or not since it contains the consumerSecret and Key? 

Best Answer
0 Votes

Are you using OAuth 1.0a or OAuth 2.0? I encourage you to try OAuth 2.0, as it is easier to use and would not require signature creation.

Best Answer
0 Votes

Ah, I could have sworn I read somewhere that if we were just starting an app to do 1.0 since 2.0 just came out for a beta. 

 

Guess I'll start looking into 2.0 then 😛 ...

 

On that note as well, any chance of pointing me in the right direction for doing the callback url for apps? Been searching around but don't see quite what/how I'm supposed to make it work...

You must specify the full callback URI in your application settings on dev.fitbit.com

but when I go the my application settings I don't see a place to put a callback url or what it would/should be even...I saw somewhere online that doing http://localhost:8553 should send it back to my application but doesn't seem to work. Tried making 2.0 

 

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=229PH8&redirect_uri=http://localhost:8553&scope=activity%20profile%20sleep%20social

 

but I get

 

The app you're trying to connect did not provide valid information to Fitbit. Please report this issue to them.

Developer information: invalid_request - Invalid redirect_uri parameter value

 

 

Also...not sure if you guys are aware, but in the app registration/editing all of the pink "?" don't do anything currently it seems? 

Best Answer
0 Votes

@SunsetRunner wrote:

Ah, I could have sworn I read somewhere that if we were just starting an app to do 1.0 since 2.0 just came out for a beta. 


We're not recommending it for production use, as we may need to make backwards incompatible changes with less than 30 days notice and there may be bugs. But depending on your use case, this may be acceptable given how much easier it is to use.

 

Your redirect_uri value must be fully specified in your application settings on https://dev.fitbit.com/ . Make sure that you URI encode your redirect_uri value. If your callback URL is http://localhost:8553, it'd look like:

 

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=229PH8&redirect_uri=http%3A%2F%2Flocalhost%3A8553&scope=activity%20profile%20sleep%20social

 

 

Best Answer
0 Votes

The link you put is exactly what I was needing to get the api to recognize the application at least. 

 

Guess I just gotta figure out how to get the callback now cause it doesn't seem to be actually redirecting anywhere 😞

Best Answer
0 Votes

K, 

 

Next step in the game. I've finally found something that lets me grab the return url after a user accepts. 

 

What do I do now 😛

 

I'm not versed very well in web programming/development but it just seems that I need to do a GET request but I'm not sure how that exactly works.  Still trying to do it in Unity and I think it has to be done with wwwform...any chance someone can confirm this?

 

Is it possible to get back data without having to do a Get request? Like similar to how you can just build the URL for the oauth token request? 

 

Looking at the documentation I can't figure out what URL I would send the token + auth headers to anyways as for example,

https://api.fitbit.com/1/user/-/profile.json

is what it says. What should I be filling in here even? 

 

I just get 

{"errors":[{"errorType":"oauth","fieldName":"n/a","message":"No Authorization header provided in the request. Each call to Fitbit API should be OAuth signed"}],"success":false}

When I just try navigating to it.  

Best Answer
0 Votes