AS3 Trophy API

Forum Listing » Game Achievements Forum » View Topic


  • Hopefully I've got everything down. I was hoping some people could test this out for me.

    http://www.experimentalflash.com/resources/Game_Files/AS3_API.zip

    http://pastebin.com/raw.php?i=2qZnTN9a - Improved version with Game Sessions

    I'm *pretty* sure everything works...Not completely, though. Please test for me =P


    Format :

    Every function will require the GameID and your PrivateKey for every call.

    >Authorize User
      -Function name: authUser
      -Parameters:
         -gameID:int
         -privKey:String
         -userName:String
         -userToken:String
         -callBack:Function
      -Return Type: Boolean
      -Use
         -Authorizes a user by getting their User Name, and User Token. Requires a function with one
          Boolean parameter


    >Adding Trophies
      -Function name: addTrophyAchieved
      -Parameters:
         -gameID:int
         -privKey:String
         -userName:String
         -userToken:String
         -trophyID:int
      -Return Type: Void
      -Use
         -Adds a trophy to a specific User, using the trophy's ID.


    >Getting Trophy Data
      -Function name: getTrophyData
      -Parameters:
         -gameID:int
         -privKey:String
         -userName:String
         -userToken:String
         -type:* (String or int)
         -callBack:Function
      -Return Type: Array
      -Use
         -Gets trophy data from a user a user by getting their User Name, and User Token. Type can
          be ("all", "true", "false", or int). "all" will return all trophies for the game. "true" will return
          only the trophies that have been chieved by that user. "false" will return only trophies not
          achieved by that user. An int will return data from a trophy with that ID. Requires a function
          passed in with one Array parameter.

          The Array being passed back will be in this format:
             secondNum is the number of the trophy, starting at 0. Getting data from your third trophy
             would require a secondNum of 2

             >The ID of the trophy
                 Array["id"][secondNum]

             >The Title of the trophy
                 Array["title"][secondNum]

             >The Description of the trophy
                 Array["description"][secondNum]

             >The Difficulty of the trophy
                 Array["difficulty"][secondNum]

             >The URL of the trophy image
                 Array["image_url"][secondNum]

             >Whether the trophy was achieved, and if so, the date it was
                 Array["achieved"][secondNum]


    >Getting Highscore Data
      -Function name: getHighscores
      -Parameters:
         -gameID:int
         -privKey:String
         -callBack:Function
         -userName:String (optional)
         -userToken:String (optional)
         -ilmit:int (optional)
      -Return Type: None right now
      -Use
         -Doesn't work completely as of yet. But it will return data gotten from the site. Will require a function with one Array parameter.


    >Setting Highscore Data
      -Function name: setHighscore
      -Parameters:
         -gameID:int
         -privKey:String
         -score:String
         -sort:int
         -userName:String
         -userToken:String (optional)
         -extraData:String (optional)
      -Return Type: Void
      -Use
         -Score may not have spaces or special characters apart from those that would interfere with
          URL caching. userToken is required if the userName is not a guest.



    >Setting Game Data
      -Function name: setKeyData
      -Parameters:
         -gameID:int
         -privKey:String
         -key:String
         -gameData:String
         -userName:String (optional)
         -userToken:String (optional)
      -Return Type: Void
      -Use
         -Stores game data for later retreival. userName and userToken are left blank if this data
          should be stored for the game, rather than a user.


    >Getting Game Data
      -Function name: getKeyData
      -Parameters:
         -gameID:int
         -privKey:String
         -key:String
         -callBack:Function
         -userName:String (optional)
         -userToken:String (optional)
      -Return Type: String
      -Use
         -Retieves game data previously stored. userName and userToken are left blank if this data
          should be retrieved for the game, rather than a user. Requires a function with a String
          parameter.


    >Removing Game Data
      -Function name: removeKeyData
      -Parameters:
         -gameID:int
         -privKey:String
         -key:String
         -userName:String (optional)
         -userToken:String (optional)
      -Return Type: String
      -Use
         -Removes game data previously stored. userName and userToken are left blank if this data
          should be removed for the game, rather than a user.


    >Getting Game Data Keys
      -Function name: getAllKeys
      -Parameters:
         -gameID:int
         -privKey:String
         -callback:Function
         -userName:String (optional)
         -userToken:String (optional)
      -Return Type: Array
      -Use
         -Retrives all game data KEYS previously stored. userName and userToken are left blank if this
          data should be retrieved for all the game's keys. Requires a function with one Array
          parameter.

    > Open a Session
    Function: sessionOpen
    Parameters:
        gameID : int
        privKey : String
        key : String,
        callBack : Function
        userName : String
        userToken : String
    No return type.
    Use:
     Passes a boolean true or false to the callback function passed in.

    > Ping a Session
    Function: sessionPing
    Parameters:
        same as sessionOpen() - works the same as sessionOpen too. 

    > Close a Session
    Function: sessionClose
    Parameters:
        same as sessionOpen() - works the same as sessionOpen too. 

    Last edited on August 31, 2010 - 04:06 PM by Ashley

  • This sounds great, SYG! You've even got highscores and data-storage in there! Great stuff. If I ever try flash again, I'll be sure to test this out. :)

  • Wow, man, that's pretty crazy. I'll start letting the Flash people in now. :D

  • This is great, I'm going to try to use it for my current project. Just wanted to know if the "Currently Playing" thing is in yet!

  • Sweet.

  • I updated this to support Game Sessions. Here's the new AS3_API.as file at Pastebin.org:

    http://pastebin.com/raw.php?i=2qZnTN9a

    Note: you will still need the MD5.as from SYG's original source.

    Last edited on August 31, 2010 - 04:17 PM by Ashley

  • link is broken, can someone please give me a link?

  • I see you made a new topic, Martin.

    Did you manage to get it working? If so, any chance you could upload a zip somewhere or email a zip to ashley@gamejolt.com, so we can update the links and files?

    We don't want anyone else to have the same trouble as you!

  • Yes I am able to communicate with the API successfully here is the as3 api with a compatible MD5 encryption file: http://www.mediafire.com/?uk22qd29uhj81ul

  • Sweet, just so you know, tower, you can upload it to Game Jolt as a "game". This way the file never gets lost again. Or you can upload the code to something like Github, which would be preferred, but that can be more complicated if you don't know Git.

  • You absolutely HAVE to add an Event.COMPLETE to the SetKeyData function, none of my calls are going through!


    I'll edit it myself on my end, but that needs to be an official fix!

    EDIT:

    Never mind that, I'm just too tired, and too stressed to think about anything but Events... D:

    Last edited on August 19, 2012 - 10:13 PM by Alex Ford

  • Hello!

    I'm trying to implement an highscore table and trophies for a flash (AS3) game using the API posted by 'towerismtest1', with no success.

    Using the little Windows application posted here in this forum it works perfectly -I can set an scores and trophies for me-.

    Any hints? Is this AS3 file deprecated for some reason? Have I missed something?

    In my code I am doing first a User-Auth (is it needed?), and submitting the score after the game is completed. I checked that I am getting the flashvars correctly for the username and usertoken.

    Thanks!


     

  • As of now, I've traced it to the call to authUser crashing.

  • I've been tracing and debugging the API. It has concept errors about the HTTP protocol and/or AS3 handling of the URL*.

    We're going to try to make the API work as it should, alhhoug it would be nice if someone tells us wether to launch POST or GET in the set/add calls...

    *Mainly: using method.POST implies using the urlloader.data field for putting inside the POST parameters. For a part: that is a concept error for the side of who wrote that in the API. For another part: if the .data field has nothing, AS3 puts the call as a GET no matter what you've told it to do (use Firebug and check it, as we've done), and it does that because POST calls, by the standard definition, have to have a message body, hence it sends a GET if we put nothing into that body.

    Last edited on September 15, 2012 - 06:24 AM by Hecho al Punto

  • Okay. To sum to it, I guess some call with the loader was semi-failing somewhere, so then it can't be reused (trying to reuse the same ULRLoader in AS3 is a bet because this always ends happening).


    I've just rewritten from 0 the things we use -took 10 minutes: auth the user, submit score to multiple tables, get trophy data, add trophy achieved- and it seems to be working flawlessly now, so our game will be public soon.

Friends {{client.onlineFriendsCount}}/{{client.offlineFriendsCount}}

People Online:

Room Users {{client.usersOnline.length}}

: