Sign In Register

How can we help you today?

Start a new topic
Deferred

Create downloadables from REST API

Using Unity3D.
We have defines for each level stored in XML files which we would like to put in downloadables.
That way we can change the levels and even add new ones without it being required for our players to update the game.
Right now for each new level we add, we have to first go to the downloadables section on the portal to create the shortcode and upload the xml there.

We can already update the levels using the REST API, but it would be very helpful if we could create new ones as well from within the Unity Editor.
(Now it returns: "Short code [DEF_LEVEL_2] Unknown" if we try upload a new one).

I can imagine this feature being a great addition for other types of games (like when there's a level editor for players) as well.

Is there already a way to do this?

Thanks in advance.




In newer version of GameSparks (v5.6.5.214 or they've changed something on their endpoints) for Unity the method setDownloadable of GameSparksRestApi.cs does not work. After hours trying to figure out what was wrong, it seems that the issue is in GameSparksEditorFormUpload.cs, Line 24: "binaryContentFile" should actually be "file", using the "binaryContentFile" will result in 403 Forbidden with no error message.

Hi Liam,


We are still having this issue so we are using Amazon S3 for our asset bundles for now.


1 person likes this

Hi Hjupter,


Apologies for the delayed response. I've tested this and it works fine for me and collaborators in the game. If you're still having an issue please raise a ticket and we'll investigate this for you.


Regards,

Liam


Hi Liam,


Yes they have all access I even tried myself by creating a new account added it as admin (all access) and I was getting the same error, we wanted to use downloadables feature for asset bundles but this is stopping us.


I tried using the restv2 API but I get this error: The remote server returned an error: (500) Server Error.


 https://docs2.gamesparks.com/api-documentation/rest-apis/game-configuration.html#!/game.downloadables/post_restv2_game_apiKey_config_~downloadables_downloadableId_file
 

I tried basic and GSAccessToken authentication nothing worked.

Hi Liam,


Yes they have all access. I tried changing the code to use the rest api here:

https://docs2.gamesparks.com/api-documentation/rest-apis/game-configuration.html#!/game.downloadables/post_restv2_game_apiKey_config_~downloadables_downloadableId_file


But I'm getting this error: 

{"responseCode":-1,"errorMessage":"The remote server returned an error: (500) Server Error."}


I tried using basic authorization and X-GSAccessToken none of them worked,

Hi Hjupter,


Are these users set as gameAdmins in the project ? 


Regards,

Liam

@Liam I implemented this code into an Asset Bundle system so I can upload them it works fine then I tried to add other people into the project and when they tried it doesn't allow them they get 403 error, looks like this only works with the owner account.


1 person likes this

Hi Enrico,


There is basic support for this within the Unity Editor. If you click "GameSparks" in the top bar in the editor and then select "Rest Api" the following window will pop up.


image


You can then add the shortCode, your portal userName and password and selected file. Then hit POST. This file should now be in your Downloadables on the portal. You can also upload directly through our documentation page here.


Thanks,

Liam



1 person likes this

Any help from the official support?

I'm asking for an official solution on the unity sdk not for a workaround :) but thanks

See my previous comment, this is exactly what I needed as well. Code is included in comment

Is there an easy way to do this from the Gamespark Unity SDK?

I have a bunch of level data file I would like to upload to the "Downloadables" section but I can't figure out an easy way to do it, am I missing something?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
 public class Upload
{
 
 
    public void UploadFile()
    {
       System.Net.ServicePointManager.ServerCertificateValidationCallback +=
  delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
  System.Security.Cryptography.X509Certificates.X509Chain chain,
  System.Net.Security.SslPolicyErrors sslPolicyErrors)
  {
  return true; // **** Always accept
  };
       private static string HOST = "https://portal.gamesparks.net/";

       private static string REST_URL = HOST + "rest/";
       string apiKey, string username, string password, string shortCode, string fileName;
       string url = REST_URL + apiKey + "/binarycontent/" + shortCode;

  String ret = null;
       FileParameter param = new FileParameter(GetBytesFromFile(fileName), Path.GetFileName(fileName));
  param.FileName = fileName;

  IDictionary<string, object> postParams = new Dictionary<string, object>();
  postParams.Add("binaryContentFile", param);

  return MultipartFormDataPost(url, postParams, username, password);
       
   }
}

 

I'll have to look closer at their cs code...

thanks for the tip!

The setDownloadable function in GameSparksRestApi.cs (Unity api) properly replaces existing downloadables of the same name. So automated creation/update works fine now.

Login to post a comment