{"__v":2,"_id":"570fd0d7fda5082400ebccbe","category":{"__v":3,"_id":"56af6d6ecc4cbd0d00ce2c88","pages":["56af6e8460a37a0d00ed87ac","56af71e58be2ea0d00b48887","56af73a08be2ea0d00b48890"],"project":"56abbf55f25f160d00e17f4e","version":"56abbf55f25f160d00e17f51","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-01T14:36:30.275Z","from_sync":false,"order":2,"slug":"concepts","title":"Kongregate APIs & Concepts"},"parentDoc":null,"project":"56abbf55f25f160d00e17f4e","user":"56abbec30b9e0b0d00616274","version":{"__v":12,"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-14T17:18:15.441Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":12,"body":"## Kongregate Shared Content API\n\nKongregate's Content Sharing API makes it easy for developers to add features like custom level sharing to your games. The API gives your players the ability to:\n\n*   **Save** in-game content like levels, characters and game customizations to Kongregate's servers for easy retrieval any time and from any computer.\n*   **Browse** publicly shared, user-generated content through a [Kongregate hosted UI](http://cdn2.kongregate.com/assets/files/0000/0313/content_lightbox.png)\n*   **Share** in-game content easily via direct links, email or by posting to top social media sites. (No more copying and pasting of long, ugly text strings!)\n\nWe urge you all to check out the first integration of level sharing in [Hexiom: Connect](http://www.kongregate.com/games/Moonkey/hexiom-connect) and view the following API documents for more information:\n\n* [SharedContent.Save](doc:client-api-sharedcontent-save) \n* [SharedContent.Browse](doc:sharedcontentbrowse)\n* [SharedContent.AddLoadListener](doc:client-api-sharedcontent-addloadlistener)\n\n## Saving shared content on sites other than Kongregate\n\nYou may submit shared content created in versions of your game hosted on sites other than Kongregate. The API simply consists of a set of URL parameters you pass along with a GET request to your game's URL on Kongregate.\n\nThe relevant query parameters are `type`, `content`, and optionally, `label`. Note that this method is more limited in terms of the size of the content due to browser limitations with passing through a URL - they need to be limited to under 2,000 characters after encoding in order to ensure that it will work.\n\nAdditionally, a trailing `&z` must be appended to the URL to indicate the content was not truncated.\n\n### Example\n\nThis snippet is a simple function that accepts the relevant arguments and forwards them to Kongregate:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"function toQueryString(params:Object):String {\\n  var q:Array = [];\\n  for (var p:String in params) {\\n    q.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));\\n  }\\n  return q.join('&');\\n}\\n\\nfunction saveRemote(kongregateGameUrl:String, type:String,  \\t\\t\\t  \\n                    content:String, label:String=null):void {\\n  var loc:String = kongregateGameUrl + '?' + toQueryString({\\n    'type': contentType,\\n    'content': content,\\n    'label': label\\n  }) + '&z';\\n\\n  // Make sure your URL isn't going to be too long to send through a browser\\n  if (loc.length < 2000) {\\n    navigateToURL(new URLRequest(loc), '_blank');\\n  } else {\\n  \\ttrace('shared content too large');\\n  }\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"ActionScript 3\"\n    },\n    {\n      \"code\": \"function toQueryString(params) {\\n  var q = [];\\n  for (var p in params) {\\n    q.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));\\n  }\\n  return q.join('&');\\n}\\n\\nfunction saveRemote(kongregateGameUrl, type, content, label) {     \\n  var loc = kongregateGameUrl + '?' + toQueryString({\\n    'type': contentType,\\n    'content': content,\\n    'label': label\\n  }) + '&z';\\n\\n  // Make sure your URL isn't going to be too long to send through a browser\\n  if (loc.length < 2000) {\\n    window.open(loc);\\n  } else {\\n  \\talert('shared content too large');\\n  }\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"JavaScript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"shared-content","type":"basic","title":"Shared Content"}
## Kongregate Shared Content API Kongregate's Content Sharing API makes it easy for developers to add features like custom level sharing to your games. The API gives your players the ability to: * **Save** in-game content like levels, characters and game customizations to Kongregate's servers for easy retrieval any time and from any computer. * **Browse** publicly shared, user-generated content through a [Kongregate hosted UI](http://cdn2.kongregate.com/assets/files/0000/0313/content_lightbox.png) * **Share** in-game content easily via direct links, email or by posting to top social media sites. (No more copying and pasting of long, ugly text strings!) We urge you all to check out the first integration of level sharing in [Hexiom: Connect](http://www.kongregate.com/games/Moonkey/hexiom-connect) and view the following API documents for more information: * [SharedContent.Save](doc:client-api-sharedcontent-save) * [SharedContent.Browse](doc:sharedcontentbrowse) * [SharedContent.AddLoadListener](doc:client-api-sharedcontent-addloadlistener) ## Saving shared content on sites other than Kongregate You may submit shared content created in versions of your game hosted on sites other than Kongregate. The API simply consists of a set of URL parameters you pass along with a GET request to your game's URL on Kongregate. The relevant query parameters are `type`, `content`, and optionally, `label`. Note that this method is more limited in terms of the size of the content due to browser limitations with passing through a URL - they need to be limited to under 2,000 characters after encoding in order to ensure that it will work. Additionally, a trailing `&z` must be appended to the URL to indicate the content was not truncated. ### Example This snippet is a simple function that accepts the relevant arguments and forwards them to Kongregate: [block:code] { "codes": [ { "code": "function toQueryString(params:Object):String {\n var q:Array = [];\n for (var p:String in params) {\n q.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));\n }\n return q.join('&');\n}\n\nfunction saveRemote(kongregateGameUrl:String, type:String, \t\t\t \n content:String, label:String=null):void {\n var loc:String = kongregateGameUrl + '?' + toQueryString({\n 'type': contentType,\n 'content': content,\n 'label': label\n }) + '&z';\n\n // Make sure your URL isn't going to be too long to send through a browser\n if (loc.length < 2000) {\n navigateToURL(new URLRequest(loc), '_blank');\n } else {\n \ttrace('shared content too large');\n }\n}", "language": "javascript", "name": "ActionScript 3" }, { "code": "function toQueryString(params) {\n var q = [];\n for (var p in params) {\n q.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p]));\n }\n return q.join('&');\n}\n\nfunction saveRemote(kongregateGameUrl, type, content, label) { \n var loc = kongregateGameUrl + '?' + toQueryString({\n 'type': contentType,\n 'content': content,\n 'label': label\n }) + '&z';\n\n // Make sure your URL isn't going to be too long to send through a browser\n if (loc.length < 2000) {\n window.open(loc);\n } else {\n \talert('shared content too large');\n }\n}", "language": "javascript", "name": "JavaScript" } ] } [/block]