forum

using osu!api v2 to get user profile...

posted
Total Posts
8
Topic Starter
RongXiaoli
uhh, how can i get a client credential?
when i send a POST request i recieved a 400 code...
(should i post my source code here?
norizon
Yes, describing what you've tried and perhaps posting the error may be helpful (make sure to hide sensitive information e.g., your client secret though).

Also, you can check out the example here.
KerLq
You need to attach your token in the header, that means you have to login before
Corne2Plum3
Would help if you post the code, because what language you are using...
Dynam1cNET
The flow is really simple. Since you only wanna get public data (Profile Information) i suggest you to use the public API / Guest Tokens tokens. You start by Registering a oauth client in the settings of your profile (waay down). i guess you already have that. then you make a POST request to "https://osu.ppy.sh/oauth/token" with the Headers of the datatypes. in your case is both json. So: Accept:application/json and Content-Type:application/json. then you put in a json encoded body.

{
"client_id":1xxxx, //Your Client ID
"client_secret":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Yout client Secret (both from your oauth client)
"grant_type":"client_credentials", //dont change this
"scope":"public" //dont change this
}

you should get a response (Json encoded) with a expire date (in seconds) and a access token. That token you will need in the next step.

Now we prepare your actual request.

You will (i think that is what you want) need to make a GET request to: "https://osu.ppy.sh/api/v2/users/<USERID>/<GAMEMODE>"
so in my case "https://osu.ppy.sh/api/v2/users/12540789/osu"

We put in the same two headers in as before. (Accept and Content-Type). and a third Header called "Authorization" with the value "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" (xxx... is that long thing we got from the request before). If you send that you will be greeted with a looong json of the profile data. Here is my response:
https://haste.dynam1c.net/nmaantnn11.json

Hope i was able to help out a bit. Happy coding <3
TehPigYT
Looks like this does not work for me, I always get undefined upon request a user profile.
I have tried using both user ID and username but both of them return the same result.
I have created the Application, I got the Client ID and Client Secret and using those, I get the access token, I add that in as a third header while making the user profile request, but nothing is being returned.

Is there any possible fix?
norizon

TehPigYT wrote:

Looks like this does not work for me, I always get undefined upon request a user profile.
I have tried using both user ID and username but both of them return the same result.
I have created the Application, I got the Client ID and Client Secret and using those, I get the access token, I add that in as a third header while making the user profile request, but nothing is being returned.

Is there any possible fix?
Wdym third header? Did you also prepend the token with "Bearer "? Let us know the status code you got.
TehPigYT
Looks like the issue was actually because of the incorrect way of returning the data.
The API itself was sending the information properly.

The issue has now been resolved.
Please sign in to reply.

New reply