{"id":6846,"date":"2012-12-12T12:00:32","date_gmt":"2012-12-12T03:00:32","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=6846"},"modified":"2021-04-27T15:03:56","modified_gmt":"2021-04-27T06:03:56","slug":"integrate-gree-platform-sdk-into-your-cocos2dx-game-for-android","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/","title":{"rendered":"Integrate GREE Platform SDK into your cocos2dx game for Android"},"content":{"rendered":"<p>Hi everyone, I'm kazuma from GREE. I have a strong interest in cross-platform development tools that allow developers to write code once and deploy to multiple platforms.<\/p>\n<h3 id=\"hs_b966da15c2d590b74277253bf5c31964_header_0\">Integrate GREE Platform SDK into your cocos2dx game for Android (will support iOS in the future)<\/h3>\n<p>This guide provides step-by-step instructions on how to integrate GREE SNS features (User information, FriendList, Payment, Achievement, Leaderboard and so on) with your cocos2dx applications.<\/p>\n<p>This article is a little bit lengthy, but I hope it will be interesting for you, and inspire you to try it out yourself.<\/p>\n<p><a rel=\"attachment wp-att-6877\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/overall\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6877\" title=\"overall\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/overall-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/overall-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/overall-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/overall.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_1\"><span style=\"font-size: medium;\">Requirements<\/span><\/h4>\n<p>You should have Eclipse with the Android Developer Tools installed. If not, please setup your environment with the instructions at:<br \/>\n<a href=\"http:\/\/developer.android.com\/sdk\/installing\/installing-adt.html\">http:\/\/developer.android.com\/sdk\/installing\/installing-adt.html<\/a><\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_2\"><span style=\"font-size: medium;\">Get GREE Platform SDK for Android<\/span><\/h4>\n<p>The latest version of the GREE Platform SDK is available from:<br \/>\n<a href=\"https:\/\/developer.gree.net\">https:\/\/developer.gree.net<\/a><br \/>\n<a href=\"https:\/\/developer.gree.net\/en\/\">https:\/\/developer.gree.net\/en\/<\/a><br \/>\nPlease download the SDK for Android. Instructions in this article are written for GREE SDK version v3-3-8.<\/p>\n<p>You can also find a Developer's Guide at the URL above. Please follow the instructions in the guide and import the SDK into Eclipse.<br \/>\nTo activate your GREE Application, you need a GREE Application Id, Consumer Key, Consumer Secret, and edit your config files so that they are properly set. I will show you how to do that later in this guide.<br \/>\nDetailed instructions can also be found in the Developer's Guide at the URL above.<\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_3\"><span style=\"font-size: medium;\">Get AndroidNDK<\/span><\/h4>\n<p>Cocos2dx is written in C++ and needs to be built with AndroidNDK.<br \/>\nAndroidNDK is available from:<br \/>\n<a href=\"http:\/\/developer.android.com\/tools\/sdk\/ndk\/index.html\">http:\/\/developer.android.com\/tools\/sdk\/ndk\/index.html<\/a><br \/>\nPlease download and extract it to the  proper location on your machine.<\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_4\"><span style=\"font-size: medium;\">Get Cocos2d-x and GREE Platform SDK for Cocos2d-x<\/span><\/h4>\n<p>Now that you've finished setting up the basic environment for developing a cocos2dx application, its time to start building it. Get GREE Platform SDK for Cocos2d-x.<\/p>\n<pre class=\"superpre sh\">\n$git clone https:\/\/github.com\/gree\/GreePlatformSDKCocos2dx.git\n$cd GreePlatformSDKCocos2dx    # top of the cloned directory\n$.\/setup.sh<\/pre>\n<p>setup.sh downloads cocos2dx source code and adds GREE Platform SDK for Cocos2d-x code to it. It also provides a sample application which connects to the GREE Platform.<\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_5\"><span style=\"font-size: medium;\">Create a cocos2dx project<\/span><\/h4>\n<pre class=\"superpre sh\">\n$cd cocos2dx-2.0-x-x.x.x<\/pre>\n<p>Normally you would create a cocos2dx application project with create-android-project.sh. With this binding however, we shall use create-android-gree-project.sh to create a cocos2dx application that connects to the GREE Platform. create-android-gree-project.sh requires both Android NDK and Android SDK, so you need specify their paths for the script to execute properly. You can directly modify create-android-gree-project.sh, or set their paths as as environmental variables.<\/p>\n<pre class=\"superpre sh\">\n$export NDK_ROOT=\/home\/hoge\/xxxx; export ANDROID_SDK_ROOT=\/home\/hoge\/....; .\/create-android-gree-project.sh<\/pre>\n<p>You will get a couple of prompts. Please provide values for the fields requested.<br \/>\n\"Name of package\"<br \/>\n\"API version your app support\"<br \/>\n\"Project name of your app\"<\/p>\n<pre class=\"superpre sh\">\nuse global definition of NDK_ROOT: \/Users\/hoge\/Work\/android-ndk-r8b\/\nuse global definition of ANDROID_SDK_ROOT: \/Users\/hoge\/Work\/android-sdk-macosx\/\nInput package path. For example: org.cocos2dx.example\norg.cocos2dx.greetest\nNow cocos2d-x supports Android 2.2 or upper version\nAvailable Android targets:\n----------\nid: 1 or \"android-12\"\nName: Android 3.1\nType: Platform\nAPI level: 12\nRevision: 3\nSkins: WXGA (default)\nABIs : armeabi\n----------\n. . .\n----------\ninput target id:\n1\ninput your project name:\ngreetest\nCreated project directory: \/Users\/hoge\/Work\/GreePlatformSDKCocos2dx\/cocos2d-2.0-x-2.0.4\/greetest\/proj.android\n. . .\nResolved location of library project to: \/Users\/hoge\/Work\/GreePlatformSDKCocos2dx\/cocos2d-2.0-x-2.0.4\/cocos2dx\/platform\/android\/java\nUpdated project.properties\nUpdated local.properties\nUpdated file \/Users\/hoge\/Work\/GreePlatformSDKCocos2dx\/cocos2d-2.0-x-2.0.4\/greetest\/proj.android\/proguard-project.txt<\/pre>\n<p>Now you have a cocos2dx sample application that connects to the GREE Platform.<br \/>\n<a rel=\"attachment wp-att-6886\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/dir\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6886\" title=\"dir\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dir-600x355.png\" alt=\"\" width=\"600\" height=\"355\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dir-600x355.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dir-276x163.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dir.png 767w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_6\"><span style=\"font-size: medium;\">Build the project<\/span><\/h4>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_7\"> Add the project<\/h5>\n<p>Launch Eclipse, and add the created project and cocos2dx java files.<br \/>\nFile -&gt; New -&gt; Others<br \/>\n<a rel=\"attachment wp-att-6887\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/newpj\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6887\" title=\"newpj\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj-569x400.png\" alt=\"\" width=\"569\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj-569x400.png 569w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj-276x194.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj.png 754w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/a><\/p>\n<p>Select Android -&gt; Android Project from Existing Code.<br \/>\n<a rel=\"attachment wp-att-6888\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/newpj2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6888\" title=\"newpj2\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj2-420x400.png\" alt=\"\" width=\"420\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj2-420x400.png 420w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj2-210x200.png 210w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj2.png 528w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/a><\/p>\n<p>Select the \"proc.android\" directory of the created project.<br \/>\n<a rel=\"attachment wp-att-6889\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/newpj3\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6889\" title=\"newpj3\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj3-422x400.png\" alt=\"\" width=\"422\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj3-422x400.png 422w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj3-211x200.png 211w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj3.png 526w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/a><\/p>\n<p>Select the \".\/cocos2dx\/platform\/android\/java\" directory under cocos2dx source code.<br \/>\n<a rel=\"attachment wp-att-6890\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/newpj4\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6890\" title=\"newpj4\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj4-422x400.png\" alt=\"\" width=\"422\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj4-422x400.png 422w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj4-211x200.png 211w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/newpj4.png 528w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/a><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_8\"> Project Setup<\/h5>\n<p>From the project explorer window, choose \"java\" project and select Properties. Set GreeSDK as reference library.<br \/>\n<a rel=\"attachment wp-att-6901\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/setupjp\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6901\" title=\"setupjp\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setupjp-578x400.png\" alt=\"\" width=\"578\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setupjp-578x400.png 578w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setupjp-276x190.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setupjp.png 791w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/a><br \/>\n<a rel=\"attachment wp-att-6902\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/setuppj2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6902\" title=\"setuppj2\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setuppj2-567x400.png\" alt=\"\" width=\"567\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setuppj2-567x400.png 567w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setuppj2-276x194.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/setuppj2.png 778w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p>Now you should have no errors with java. Next, you have to configure the build environment for native code.<\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_9\"> Configure the build environment for native code<\/h5>\n<p>(You can skip this step if you are going to build native code with the command line)<br \/>\nTo build native code on Eclipse, you have to install CDT for Eclipse.<br \/>\nSelect Help -&gt; Install New Software.... from the main menu, and select http:\/\/download.eclipse.org\/releases\/xxxxx, check \"C\/C++ Development Tools\", and install it.<br \/>\n<a rel=\"attachment wp-att-6907\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6907\" title=\"native\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native-501x400.png\" alt=\"\" width=\"501\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native-501x400.png 501w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native-250x200.png 250w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native.png 821w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/p>\n<p>Select File -&gt; New -&gt; Others and select C\/C++ -&gt; Convert to a C\/C++ Project (Adds C\/C++ Nature)<br \/>\n<a rel=\"attachment wp-att-6908\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6908\" title=\"native2\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native2-424x400.png\" alt=\"\" width=\"424\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native2-424x400.png 424w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native2-212x200.png 212w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native2.png 531w\" sizes=\"auto, (max-width: 424px) 100vw, 424px\" \/><\/a><\/p>\n<p>Check the project you created, and select the Makefile project from the Project type window.<br \/>\n<a rel=\"attachment wp-att-6909\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native3\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6909\" title=\"native3\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native3-305x400.png\" alt=\"\" width=\"305\" height=\"400\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native3-305x400.png 305w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native3-152x200.png 152w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native3.png 524w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/a><\/p>\n<p>From the Project Explorer window, select your project -&gt; Properties.<br \/>\nSelect C\/C++Build -&gt; Environment and add NDK_ROOT environment variable.<br \/>\n<a rel=\"attachment wp-att-6910\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native4\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6910\" title=\"native4\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native4-600x318.png\" alt=\"\" width=\"600\" height=\"318\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native4-600x318.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native4-276x146.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native4-830x440.png 830w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native4.png 1004w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Select C\/C++Build, uncheck Use default build command and set \"bash &lt; path of the build_native.sh on your machine &gt;\"<br \/>\n<a rel=\"attachment wp-att-6911\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native5\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6911\" title=\"native5\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native5-600x340.png\" alt=\"\" width=\"600\" height=\"340\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native5-600x340.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native5-276x156.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native5-830x470.png 830w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native5.png 1009w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>The steps above need to be done only once for each project.<\/p>\n<p>Now, you can build your native code with the button below.<br \/>\n<a rel=\"attachment wp-att-6912\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/native6\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6912\" title=\"native6\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/native6.png\" alt=\"\" width=\"83\" height=\"40\" \/><\/a><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_10\"> Set information required for GREE Platform<\/h5>\n<p>Set your Application Id, Consumer Key, and Consumer Secret in res\/xml\/gree_platform_configuration.xml.<\/p>\n<pre class=\"superpre xml\">\n    <applicationId>xxxxx<applicationId>\n    <consumerKey>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<\/consumerKey>\n    <consumerSecret>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<\/consumerSecret><\/pre>\n<p>Also replace \"xxxxx\" in AndroidManifest.xml with your Application Id.<\/p>\n<pre class=\"superpre xml\">\n    <android:scheme=\"greeappxxxxx\">\n    <android:scheme=\"greeappopenxxxxxx\"><\/pre>\n<p>These steps are the same as the steps performed when creating an android application for the GREE platform.<\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_11\"> Launch Application<\/h5>\n<p>Your are now ready to run the application. It should show up like this:<br \/>\n<a rel=\"attachment wp-att-6917\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/app\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6917\" title=\"app\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/app-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/app-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/app-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/app.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>You can log in to GREE Platform by clicking on the icon in the top right corner.<br \/>\n<a rel=\"attachment wp-att-6924\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/login\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6924\" title=\"login\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/login-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/login-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/login-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/login.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>The default sample app, \"GreeBasicSample\", includes Authorizer, Dashboard, User, Friends, Payment, Achievement, Leaderboard APIs.<br \/>\n<a rel=\"attachment wp-att-6918\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/list\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6918\" title=\"list\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/list-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/list-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/list-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/list.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h4 id=\"hs_b966da15c2d590b74277253bf5c31964_header_12\"><span style=\"font-size: medium;\">How to use each API<\/span><\/h4>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_13\">General<\/h5>\n<p>To use GREE Platform SDK extensions,<\/p>\n<pre class=\"superpre cpp\">\n#include \"cocos-gree-ext.h\"\nUSING_NS_CC_GREE_EXT;\n....<\/pre>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_14\">Callbacks<\/h5>\n<p>GREE Platform SDK uses callbacks for several APIs.  To implement them, please inherit CCGreePlatformDelegate class. In the default sample:<\/p>\n<pre class=\"superpre cpp\">\nclass Helloworld : public cocos2dx::gree_extension::CCGreePlatformDelegate {<\/pre>\n<p>Next, call the setDelegatexxxx method,  and implement callback method to be called.<br \/>\nIf you'd like to catch authorizeAuthorized, authorizeError, and authorizeCancel callbacks of the Authorizer APIs -- authorizeAuthorized, authorizeCancel, authorizeError --.  please override them in HelloWorld.h.<\/p>\n<pre class=\"superpre cpp\">\nvirtual void authorizeAuthorized();\nvirtual void authorizeError();\nvirtual void authorizeCancel();<\/pre>\n<p>If you don't need to handle a specific callback, you don't have to implement it. (for example, it is okay to leave the authorizeCancel method without implementing it, if you don't need to catch the cancel callback)<\/p>\n<p>In HelloWorld.cpp:<\/p>\n<pre class=\"superpre cpp\">\n\nxxxxx {\n    CCGreePlatform::setAuthorizerDelegate(this);\n}\n\nvoid HelloWorld::authorizeAuthorized(){\n}\nvoid HelloWorld::authorizeError(){\n}<\/pre>\n<p>The available callbacks are shown in the corresponding CCGreeXXXXDelegate class in each CCGreeXXXX.h file.  For example, if you'd like to get loadThumbnail callback, the prototype of the method is:<\/p>\n<pre class=\"superpre cpp\">\nvirtual void loadThumbnailSuccess(CCGreeUser *user, CCImge *img)<\/pre>\n<p>This callback returns thumbnail data as a CCImage. You can use it for example in the following way:<\/p>\n<pre class=\"superpre cpp\">\n    CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addUIImage(img, \"key_name\");\n    CCSprite *icon = CCSptite::spriteWithTexture(tex);<\/pre>\n<p>You can do anything with it as you could with a sprite; draw, move, scale and so on.<br \/>\n<strong>Note: Callbacks don't run on the UI thread, so you cannot perform draws in callbacks.<\/strong><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_15\">Authorizer API<\/h5>\n<p>The basic usage of the Authorizer API is:<\/p>\n<pre class=\"superpre cpp\">\nxxxxx{\nCCGreePlatform::setAuthorizerDelegate(this);\n    if(CCGreeAuthorizer::isAuthorized() != true){\n        CCGreeAuthorizer::authorize();\n    }\n}\n\n\/\/To get Callbacks\nvoid HelloWorld::authorizeAuthorized(){\n}\nvoid HelloWorld::authorizeError(){\n}\nvoid HelloWorld::authorizeCancel(){\n}<\/pre>\n<p>If you'd like to log out, call the logout method:<\/p>\n<pre class=\"superpre cpp\">\nxxxxx{\n    CCGreeAuthorizer::logout();\n}\n\n\/\/ To get Callbacks\nvoid HelloWorld::logoutLogouted(){\n}\nvoid HelloWorld::logoutError(){\n}\nvoid HelloWorld::logoutCancel(){\n}<\/pre>\n<p><a rel=\"attachment wp-att-6929\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/logout\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6929\" title=\"logout\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/logout-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/logout-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/logout-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/logout.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>You can also get Authorizer related information.<\/p>\n<pre class=\"superpre cpp\">\nCCString *token = CCGreeAuthorizer::getOAuthAccessToken();\nCCString *secret = CCGreeAuthorizer::getOAuthAccessTokenSecret();<\/pre>\n<p>Currently supported APIs are:<\/p>\n<pre class=\"superpre cpp\">\nclass CCGreeAuthorizer\n{\n    public:\n        static void authorize();  \/\/ async\n        static void authorize(int user_grade); \/\/ async\n        static bool isAuthorized();\n        static bool hasOAuthAccessToken();\n        static CCString *getOAuthAccessToken();\n        static CCString *getOAuthAccessTokenSecret();\n\n        static void logout(); \/\/ async\n}<\/pre>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_16\">User and Friend APIs<\/h5>\n<p>With User and Friend APIs, you can get user information (e.g. name, age, gender and so on) of users,  as well their friends' information.<br \/>\nTo get login user information:<\/p>\n<pre class=\"superpre cpp\">\n     CCGreeUser *user = CCGreePlatform::getLocalUser();\n     CCString *nickName = user->getNickname();\n     CCString *dispName = user->getDisplayName();\n     CCString *id = user->getId();\n     CCString *region = user->getRegion();\n     CCString *subRegion = user->getSubregion();\n     CCString *lang = user->getLanguage();\n     CCString *timeZone = user->getTimezone();\n     CCString *me = user->getAboutMe();\n     CCString *birthDay = user->getBirthday();\n     CCString *gender = user->getGender();\n     CCString *age = user->getAge();\n     CCString *blood = user->getBloodType();\n     bool hasApp = user->getHasApp();\n     CCString *hash = user->getUserHash();\n     CCString *type = user->getUserType();\n     int grade = user->getUserGrade();<\/pre>\n<p>To load the user's avatar thumbnail:<\/p>\n<pre class=\"superpre cpp\">\n    user->loadThumbnail(THUMBNAIL_SIZE_HUGE); \/\/ you can specify the size of the thumbnail to be downloaded.\n\n\/\/Refer to the information regarding thumbnail callbacks to handle the response.<\/pre>\n<p>To get a list of friends:<\/p>\n<pre class=\"superpre cpp\">\n    user->loadFriends(1, 10); \/\/first argument specifies the startIndex, second argument specifies the number of friends to load.\n\n\/\/ Callbacks for loadFriends\nvoid HelloWorld::loadFriendsSuccess(CCGreeUser *user, int index, int count, CCArray *userArray){\n}\nvoid HelloWorld::loadFriendsFailure(CCGreeUser *user, int responseCode, CCString *response){\n}\n\/\/ Friends information retrieved will be stored in a CCArray which can be easily iterated over.<\/pre>\n<p><a rel=\"attachment wp-att-6930\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/user\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6930\" title=\"user\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/user-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/user-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/user-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/user.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Currently supported APIs are:<\/p>\n<pre class=\"superpre cpp\">\nclass CC_DLL CCGreeUser : public CCObject\n{\n    public:\n        CCString *getNickname();\n        CCString *getDisplayName();\n        CCString *getId();\n        CCString *getRegion();\n        CCString *getSubregion();\n        CCString *getLanguage();\n        CCString *getTimezone();\n        CCString *getAboutMe();\n        CCString *getBirthday();\n        CCString *getGender();\n        CCString *getAge();\n        CCString *getBloodType();\n        bool      getHasApp();\n        CCString *getUserHash();\n        CCString *getUserType();\n        int getUserGrade();\n\n        bool     loadThumbnail(int size);  \/\/ async\n        void     loadFriends(int offset, int count); \/\/ async\n        void     loadIgnoredUserIds(int offset, int count); \/\/async\n        void     isIgnoringUserWithId(CCString *pid); \/\/async\n}<\/pre>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_17\">Payment APIs<\/h5>\n<p>You can create Payment items and submit Payment requests. To submit a Payment request, you have to create Payment Items first, and specify them in the request.<\/p>\n<pre class=\"superpre cpp\">\n    CCGreePaymentItem *item1 = CCGreePaymentItem::create(\"01234\", \"TestItem1\", 100, 20);\n    CCGreePaymentItem *item2 = CCGreePaymentItem::create(\"56789\", \"TestItem2\", 200, 30);\n    \/\/ arg1 : itemId, arg2 : itemName, arg3 : unitPrice, arg4 : quantity\n\n    CCArray *itemArray = new CCArray();\n    itemArray->addObject(item1);\n    itemArray->addObject(item2);\n\n    \/\/ to enable callbacks\n    CCGreePlatform::setPaymentDelegate(this);\n\n    CCGreePayment *pay = CCGreePayment::create(\"Payment Test\", itemArray);\n    \/\/ arg1 : message to be displayed on payment screen\n\n    pay->request();\n}\n\n\/\/ Callbacks\nvoid HelloWorld::paymentRequestSuccess(CCGreePayment *payment, int responseCode, CCString* paymentId){\n}\nvoid HelloWorld::paymentRequestCancel(CCGreePayment *payment, int responseCode, CCString* paymentId){\n}\nvoid HelloWorld::paymentRequestFailure(CCGreePayment *payment, int responseCode, CCString *paymentId, CCString *response){\n}<\/pre>\n<p><a rel=\"attachment wp-att-7049\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/pay-2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7049\" title=\"pay\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/pay1-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/pay1-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/pay1-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/pay1.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Implement callback methods as required.<\/p>\n<p>Currently supported APIs are:<\/p>\n<pre class=\"superpre cpp\">\nclass CCGreePaymentItem : public CCObject\n{\n        public:\n                void setImageUrl(const char *url);\n                void setDescription(const char *desc);\n                CCString *getItemId();\n                CCString *getItemName();\n                double getUnitPrice();\n                int getQuantity();\n                CCString *getImageUrl();\n                CCString *getDescription();\n}\n\nclass CCGreePayment\n{\n        public:\n                void request();  \/\/ async\n\n                void setCallbackUrl(const char *url);\n                void verify(const char *paymentId);  \/\/ async\n}<\/pre>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_18\">Achievement APIs<\/h5>\n<p>You can load a list of Achievements:<\/p>\n<pre class=\"superpre cpp\">\n    \/\/ to get callback\n    CCGreePlatform::setAchievementDelegate(this);\n\n    CCGreeAchievement::loadAchievements(1, 10);\n    \/\/ arg1 : start index to be loaded, arg2 : the number of the list to be loaded<\/pre>\n<p>Get the achievement list by implementing the success callback.<br \/>\nAs with the friends list, achievement items retrieved are stored in a CCArray.<\/p>\n<pre class=\"superpre cpp\">\nvoid HelloWorld::loadAchievementsSuccess(int index, int count, CCArray *elementArray)\n{\n     CCObject *it;\n        CCARRAY_FOREACH(elementArray, it){\n            CCGreeAchievement *element = dynamic_cast<CCGreeAchievement *>(it);\n        }\n    }\n}<\/pre>\n<p>You can lock\/unlock the achievements:<\/p>\n<pre class=\"superpre cpp\">\n    if(element->isUnlocked() == true){\n        element->lock();\n    }else{\n        element->unlock();\n    }<\/pre>\n<p>And get the corresponding lock\/unlock icon as a CCImage:<\/p>\n<pre class=\"superpre cpp\">\n    CCImage* icon = element->getIcon();<\/pre>\n<p>Currently supported APIs are:<\/p>\n<pre class=\"superpre cpp\">\nclass CCGreeAchievement : public CCObject\n{\n        public:\n                static void loadAchievements(int index, int count);\n\n                CCString *getId();\n                CCString *getName();\n                CCString *getDescription();\n                int getScore();\n                bool isUnlocked();\n                bool isSecret();\n                bool loadThumbnail();  \/\/ async\n                CCImage *getIcon();\n\n                void unlock();  \/\/ async\n                void lock();   \/\/ async\n}\n<\/pre>\n<p><a rel=\"attachment wp-att-7052\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/ach-2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7052\" title=\"ach\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/ach1-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/ach1-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/ach1-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/ach1.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_19\">Dashboard API<\/h5>\n<p>To launch Dashboard, simply use:<\/p>\n<pre class=\"superpre cpp\">\n    CCGreeDashboard::launch()\n    CCGreeDashboard::launch(int type, CCDictionary *params)<\/pre>\n<p><a rel=\"attachment wp-att-7048\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/dash-2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7048\" title=\"dash\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dash1-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dash1-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dash1-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/11\/dash1.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_20\">Leaderboard API<\/h5>\n<p>You can load the Leaderboard list, and get information on each item in the list:<\/p>\n<pre class=\"superpre cpp\">\n{\n    \/\/Load Leaderboard\n    CCGreePlatform::setLeaderboardDelegate(this);\n    CCGreeLeaderboard::loadLeaderboards(1, 10);\n}\n\/\/callback\nvoid HelloWorld::loadLeaderboardsSuccess(int index, int count, CCArray *leaderboardArray){\nCCGreeLeaderboard *board = dynamic_cast<CCGreeLeaderboard *>(leaderboardArray->objectAtIndex(1));\nCCString *id = board->getId();\nCCString *name = board->getName();\nCCString *url = board->getThumbnailUrl();\n}<\/pre>\n<p>Also you can set the score for each leaderboard you loaded:<\/p>\n<pre class=\"superpre cpp\">\n    board->createScore(10000);<\/pre>\n<p><a rel=\"attachment wp-att-7125\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/test2-3\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7125\" title=\"test2\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test22-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test22-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test22-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test22.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h5 id=\"hs_b966da15c2d590b74277253bf5c31964_header_21\"> Dialogs(InviteDialog, RequestDialog, ShareDialog)<\/h5>\n<p>You can create and display dialogs with this library.  Below is an example that shows how to display an InviteDialog. Pass parameters as CCDictionary, as how you would do normally with cocos2dx.<\/p>\n<pre class=\"superpre cpp\">\n    CCGreeInviteDialog *dialog = CCGreeInviteDialog::create();\n    CCDictionary *dict = CCDictionary::create();\n    dict->setObject(new CCString(xxxxxxxxxx), GD_INVITE_DIALOG_PARAM_KEY_TOUSERID);\n    dict->setObject(new CCString(xxxxxxxxxx), GD_INVITE_DIALOG_PARAM_KEY_BODY);\n    dialog->setParams(dict);\n    dialog->show();<\/pre>\n<p><a rel=\"attachment wp-att-7126\" href=\"http:\/\/labs.gree.jp\/blog\/2012\/12\/6846\/test1-3\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7126\" title=\"test1\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test1-600x336.png\" alt=\"\" width=\"600\" height=\"336\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test1-600x336.png 600w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test1-276x155.png 276w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2012\/12\/test1.png 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone, I'm kazuma from GREE. I have a strong interest in cross-platform development tools that allow dev [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[171],"class_list":["post-6846","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-info","tag-info"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/6846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=6846"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/6846\/revisions"}],"predecessor-version":[{"id":21170,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/6846\/revisions\/21170"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=6846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=6846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=6846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}