1
votes

How to get snapshot ID in Gogle Play Saved Games (I'm using the latest revision 27 of Google Play Services Library for Android)?

There is a method in com.google.android.gms.games.snapshot.Snapshots:

public abstract PendingResult<Snapshots.OpenSnapshotResult> resolveConflict (GoogleApiClient apiClient, String conflictId, String snapshotId, SnapshotMetadataChange metadataChange, SnapshotContents snapshotContents)

I can't find methods like getID()or getSnapshotID()in Snapshot/SnapshotMetadata/OpenSnapshotResult interfaces.

Documentation: https://developers.google.com/android/reference/com/google/android/gms/games/snapshot/Snapshots

2

2 Answers

-1
votes

There is no direct way to find the snapshot_id of a snapshot but you can get it like this:

  • Determine the Player_id (set to me if its current authenticated user) and make a GET request to retrieve a list of snapshots created by your application for the player corresponding to the player ID.

    GET https://www.googleapis.com/games/v1/players/playerId/snapshots
    
  • This will return the snapshot Resources in the items array.

  • The items array will contain the following JSON data:

    { "kind": "games#snapshot", "id": string, "driveId": string, "uniqueName": string, "type": string, "title": string, "description": string, "coverImage": { "kind": "games#snapshotImage", "width": integer, "height": integer, "mime_type": string, "url": string }, "lastModifiedMillis": long, "durationMillis": long }

  • The "id" value associated with this key will be the snapshot_id you are looking for.

2
votes

Getting snapshot ID for conflict resolution is actually pretty easy. Just call snapshot.getMetadata().getSnapshotId() on your snapshot and thats it.

Your resolution code may then look like this:

Snapshots.OpenSnapshotResult openSnapshotResult; //Conflicting open result

final SnapshotContents resContent = openSnapshotResult.getResolutionSnapshotContents();
//Make resolution of conflicting snapshot contents
resContent.writeBytes(...);

final Snapshot snapshot = openSnapshotResult.getSnapshot();
final String snapshotID = snapshot.getMetadata().getSnapshotId(); //Here comes your snapshot ID
Games.Snapshots.resolveConflict(PlayClient, openSnapshotResult.getConflictId(), snapshotID, SnapshotMetadataChange.EMPTY_CHANGE, resContent);

It doen't matter if you take Id of base snapshot or conflicting snapshot. They are the same.