LIKES_TO_WIN that was configured on the Developer Dashboard. The example then checks for an update message to see if the achievement has been unlocked and, if true, sets the achievement as unlocked in the app. Otherwise, the game moves on and increments the count on the achievement if a game condition is met, in this example if a win is recorded.import com.meta.horizon.platform.ovr.Error;
import com.meta.horizon.platform.ovr.models.AchievementProgress;
import com.meta.horizon.platform.ovr.models.AchievementProgressArray;
import com.meta.horizon.platform.ovr.requests.Achievements;
import com.meta.horizon.platform.ovr.requests.Request;
import java.util.List;
public class AchievementsManager {
private static String TAG = "AchievementsManager";
// API NAME defined on the dashboard for the achievement
private static final String LIKES_TO_WIN = "LIKES_TO_WIN";
// true if the local user hit the achievement Count setup on the dashboard
private boolean likesToWinUnlocked;
public boolean getLikesToWin() {
return this.likesToWinUnlocked;
}
private void checkForAchievementUpdates() {
Request<AchievementProgressArray> request =
Achievements.getProgressByName(new String[] {LIKES_TO_WIN});
request
.onSuccess(
progressArray -> {
List<AchievementProgress> elements = progressArray.getElements();
for (AchievementProgress progress : elements) {
if (LIKES_TO_WIN.equals(progress.getName())) {
this.likesToWinUnlocked = progress.getIsUnlocked();
}
}
})
.onError(
(Request.Handler<Error>) error -> Log.e(TAG, "Error getting achievement progress."));
}
public void recordWinForLocalUser() {
Achievements.addCount(LIKES_TO_WIN, 1)
.onSuccess(n -> this.checkForAchievementUpdates());
}
}
POST https://graph.oculus.com/$APPID/achievement_definitions| Parameter | Required/Optional | Description | Type | Example |
|---|---|---|---|---|
access_token | Required | Bearer token that contains OC|$APP_ID |$APP_SECRET | string | “OC|1234|456789” |
api_name | Required | The name used to reference to the achievement in this API and in the client SDK. This alphanumeric string must be unique for the app. If the achievement exists, the call will update it. If it doesn’t exist, the call will create an achievement with this name. | string | “VISIT_3_CONTINENTS” |
achievement_type | Required | This is the achievement type. There are three types of achievement, please see the description above for information on the different types. | enum with values: SIMPLE, COUNT, BITFIELD | “SIMPLE” |
achievement_write_policy | Required | Determines who is allowed to write achievement progress. Please see the description above for information on the two different write policies. | enum with values: CLIENT_AUTHORITATIVE, SERVER_AUTHORITATIVE | “CLIENT_AUTHORITATIVE” |
target | Required if achievement_type is count or bitfield | The number of event occurrences for the achievement to be unlocked. Please see the description above for more information on target. | integer | 50 |
bitfield_length | Required if achievement type is bitfield | The size of the bitfield for this achievement. | integer | 7 |
is_archived | Optional. Default is false. | Boolean that indicates if the achievement is archived. Can also be used to unarchive an achievement. Archiving does not delete the achievement or user progress. | boolean | “false” |
title | Required | The name of the achievement that the user sees. | string | “Visited 3 Continents” |
description | Required | The text description that the user sees. | string | “This achievement unlocks when...” |
unlocked_description _override | Optional | The text description that the user sees when the achievement is unlocked. | string | “Congratulations! You visited 3 continents.” |
is_secret | Optional - Default is false. | Boolean that indicates whether the achievement is hidden until earned. | boolean | “false” |
unlocked_image_file | Optional - A default image is used. | The local path to the icon shown after the achievement has been earned. Must be a 256x256 PNG file. | string | ”@/path/to/unlocked_icon.png; type=image/png” |
locked_image_file | Optional - If an unlocked image is provided, a grayscale version will be used as the locked image. Otherwise, a default is used. | The local path to the icon shown before the achievement is earned. Must be a 256x256 PNG file. | string | ”@/path/to/locked_icon.png; type=image/png” |
curl -X POST -d "access_token=OC|$APP_ID|$APP_SECRET" -d "api_name=VISIT_3_CONTINENTS" -d "achievement_type=BITFIELD" -d "achievement_write_policy=SERVER_AUTHORITATIVE" -d "target=3" -d "bitfield_length=7" -d "is_archived=false" -d "title=Achievement Title" -d "description=How to earn me" -d "unlocked_description_override=You did it" -d "is_secret=false" -d "locked_image_file=@/path/to/locked_icon.png;type=image/png" -d "unlocked_image_file=@/path/to/unlocked_icon.png;type=image/png" https://graph.oculus.com/$APPID/achievement_definitions
{"id":"1074233745960170"}
GET https://graph.oculus.com/$APPID/achievement_definitions| Parameter | Required/Optional | Description | Type | Example |
|---|---|---|---|---|
access_token | Required | Bearer token that contains OC|$APP_ID |$APP_SECRET | string | “OC|1234|456789” |
api_names | Optional | The names of the achievement definitions to fetch. If omitted all achievement definitions are returned. | string array | [“VISIT_3_CONTINENTS”, “WALK_500_MILES”] |
include_archived | Optional | Boolean that indicates whether to include archived achievements. This may only be used when an App Access Token is used to authenticate. | boolean | “false” |
fields | Optional | A comma-separated list of field names to retrieve. Can contain: api_name, achievement_type, achievement_write_policy, target, bitfield_length, is_archived, title, description, unlocked_description_override, is_secret, locked_image_uri, unlocked_image_uri. If omitted, only the IDs are returned. | String | “api_name,achievement_type” |
curl -X GET "https://graph.oculus.com/$APP_ID/achievement_definitions?fields=api_name,achievement_type,achievement_write_policy,target,bitfield_length,is_archived,title,description,unlocked_description_override,is_secret,locked_image_uri,unlocked_image_uri&api_names=\[\"VISIT_3_CONTINENTS\"\]&access_token=OC\|$APP_ID\|$APP_SECRET"
{
"data": [{
"id": "1074233745960170",
"api_name": "VISIT_3_CONTINENTS",
"achievement_type": "BITFIELD",
"achievement_write_policy": "SERVER_AUTHORITATIVE",
"target": 3,
"bitfield_length": 7,
"is_archived": false,
"title": "Achievement Title",
"description": "How to earn me",
"unlocked_description_override": "You did it",
"is_secret": false,
"locked_image_uri": "https://scontent.oculuscdn.com/...",
"unlocked_image_uri": "https://scontent.oculuscdn.com/..."
}]
}
POST https://graph.oculus.com/$USER_ID/achievements| Parameter | Required/Optional | Description | Type | Example |
|---|---|---|---|---|
access_token | Required | Bearer token that contains OC|$APP_ID |$APP_SECRET | string | “OC|1234|456789” |
api_name | Required | The names of the achievement to update. | string | “VISIT_3_CONTINENTS” |
add_count | Required if the achievement is a Count type. | Value to add to the progress counter for this achievement. Only valid for COUNT achievements. | integer | 25 |
add_bits | Required if the achievement is a Bitfield type. | Bits to add to the progress of this achievement. Only valid for BITFIELD achievements. | string | “110001” |
force_unlock | Optional - Default is false. | Instantly unlocks an achievement regardless of progress. This must be used to unlock SIMPLE achievements. | boolean | “false” |
curl -X POST -d "access_token=OC|$APP_ID|$APP_SECRET" -d "api_name=MY_ACHIEVEMENT" -d "add_count=25" -d "force_unlock=true" https://graph.oculus.com/$USER_ID/achievements
{"id":"1074233745960170","api_name":"MY_ACHIEVEMENT","just_unlocked":true}
just_unlocked that indicates if this operation caused the achievement to unlock.GET https://graph.oculus.com/$USER_ID/achievements| Parameter | Required/Optional | Description | Type | Example |
|---|---|---|---|---|
access_token | Required | Bearer token that contains OC|$APP_ID |$APP_SECRET | string | “OC|1234|456789” |
api_names | Optional | The names of the achievement definitions to fetch. If omitted all achievement definitions are returned. | string array | [“VISIT_3_CONTINENTS”, “WALK_500_MILES”] |
fields | Optional | A comma-separated list of field names to retrieve. Can contain: id, unlock_time, is_unlocked, count_progress. If omitted, only the IDs are returned. | String | “api_name,achievement_type” |
curl -X GET "https://graph.oculus.com/$USERID/achievements?access_token=OC\|$APP_ID\|$APP_SECRET&api_names=\[\"VISIT_3_CONTINENTS\"\]&fields=target,bitfield_progress,is_unlocked,unlock_time"
{
"data": [{
"id": "1074233745960170",
"bitfield_progress": "1001100",
"is_unlocked": true,
"unlock_time": 1459815726
}]
}
POST https://graph.oculus.com/achievement_remove_all| Parameter | Required/Optional | Description | Type | Example |
|---|---|---|---|---|
access_token | Required | Bearer token that contains OC|$APP_ID |$APP_SECRET | string | “OC|1234|456789” |
user_id | Required | The user ID to remove the achievements for. | string | “12345” |
curl -X POST "https://graph.oculus.com/achievement_remove_all?user_id=$USER_ID&access_token=OC\|$APP_ID\|$APP_SECRET"
{"success":true}
$VAR like $APPID and $APP_SECRET with the actual value which can be retrieved from Developer Center > Development > API.