Cocos2d-x Social and IAP Progress Thread

Hey guys,

Just to spread a bit of word around the forums.
Myself (martell) and (nickflink) on github are doing work in getting IAP SDKs into plugin-x

You can checkout all code progress here


Android IAP’s have already been merged and it is currently being used in a production game. When I have confirmed the IOS version working in production I will merge that back also.

nickflink has created a basic facebook and twitter sdk wrapper for ios and android.
I hope to build on this further with share, post features etc…

So now we wont have to pay third parties for IAP or social modules :slight_smile:

I’ll be tweeting about the progress if anyone wants to follow me to keep up to date

http://twitter.com/martellmalone

Kind Regards
Martell

Thanks for sharing.

May I ask how to use the API?
Is that we could use the same code on multi platform (IOS/Android)?

Hey winipcfg,

That is exactly the point of plugin-x. A shared c++ api to access multiple platforms :slight_smile:

This should help you :wink:

Other than the notes there it should work just like any other plugin-x sample

Martell

Hi Martell,
I request for the Amazon IAP and GameCircle.
Leaderboard for FB.

Hi KS Lam,

Android IAP will switch over to this when I find the time to do it.

That will give you Amazon, Samsung, T-Store and Yandex IAP’s
Facebook login,post and share will be done also.

Unfortunately I don’t have any intention of doing GameCircle Leaderboards,
unless Amazon or a third party wants to sponsor such a development.

Of course that doesn’t stop others from contributing such features :slight_smile:

Kind Regards
Martell

The code is in Java. How to integrate to Cocos2d-x(C++) ?

KS Lam you can call Java code from c++
(Well more specifically c++ code from Java) That’s how cocos2d-x works on Android.

Thanks for the facebook plugin Martell :slight_smile:

I have successfully integrate facebook plugin to my game. login to facebook seems to be success with this log :

D/ShareFacebook(16050): ShareFacebook.java:138:login: Session.getActiveSession 0
D/ShareFacebook(16050): ShareFacebook.java:140:login: new Session
D/ShareFacebook(16050): ShareFacebook.java:144:login: openForRead
D/ShareFacebook(16050): ShareFacebook.java:162:call: SessionState.OPENING
D/ShareFacebook(16050): ShareFacebook.java:164:call: Session.getActiveSession 0
D/ShareFacebook(16050): ShareFacebook.java:166:call: Our changing sessions isn't the active session maybe an error
D/ShareFacebook(16050): ShareFacebook.java:167:call: Session.setActiveSession 1088037520
D/ShareFacebook(16050): ShareFacebook.java:173:call: Need to login my session!
D/ShareFacebook(16050): ShareFacebook.java:152:login: Session.setActiveSession 1088037520
D/ShareFacebook(16050): ShareFacebook.java:155:login: Session.getActiveSession 1088037520

And when I tried to share something, I got this log

D/ShareFacebook(16050): ShareFacebook.java:264:networkReachable: ShareFacebook networkReachable
D/ShareFacebook(16050): ShareFacebook.java:273:networkReachable: NetWork reachable : true
D/ShareFacebook(16050): ShareFacebook.java:181:share: share invoked {SharedText=Share message : HelloShare!, SharedImagePath=CloseSelected.png}
D/ShareFacebook(16050): ShareFacebook.java:185:share: Session.getActiveSession 1088037520
D/ShareFacebook(16050): ShareFacebook.java:222:share: can not upload photo session 1088037520 in wrong state:SessionState.OPENING
D/ShareFacebook(16050): ShareFacebook.java:224:share: Session.getActiveSession 1088037520

Then nothing happens… Am I missing something here? I already added the hash code to my facebook developer app page setting.

Thank for sharing :slight_smile:

I just read your note, and I added

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        for (OnActivityResultListener listener : Cocos2dxHelper.getOnActivityResultListeners()) {
            listener.onActivityResult(requestCode, resultCode, data);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

But when I compile, I got error :
[javac] \proj.android\src\org\cocos2dx\cpp\Cocos2dxActivity.java:91: cannot find symbol
[javac] symbol : method getOnActivityResultListeners()
[javac] location: class org.cocos2dx.lib.Cocos2dxHelper
[javac] for (OnActivityResultListener listener : Cocos2dxHelper.getOnActivityResultListeners()) {
[javac] ^
[javac] 1 error

I looked on Cocos2dxHelper, and there is no method Cocos2dxHelper.getOnActivityResultListeners. So I changed to just getOnActivityResultListeners, then it compiled. But now when I invoke share function, I got this error

02-20 01:31:08.098: D/ShareFacebook(20499): ShareFacebook.java:289:networkReachable: ShareFacebook networkReachable
02-20 01:31:08.108: D/ShareFacebook(20499): ShareFacebook.java:298:networkReachable: NetWork reachable : true
02-20 01:31:08.118: D/ShareFacebook(20499): ShareFacebook.java:206:share: share invoked {SharedText=Share message : HelloShare!, SharedImagePath=CloseSelected.png}
02-20 01:31:08.118: D/ShareFacebook(20499): ShareFacebook.java:210:share: Session.getActiveSession 1088017624
02-20 01:31:08.118: D/ShareFacebook(20499): ShareFacebook.java:247:share: can not upload photo session 1088017624 in wrong state:SessionState.CLOSED_LOGIN_FAILED
02-20 01:31:08.118: D/ShareFacebook(20499): ShareFacebook.java:249:share: Session.getActiveSession 1088017624

Any clues where I might be wrong?

@siauw I haven’t done that work on the Facebook plugin
I’m sure nick appreciates it though :slight_smile:

Yes that link of code must be changed from using org.cocos2dx.lib.Cocos2dxHelper
to your Cocos2dxActivity.java

They have changed a few things recently.
I wanted to have that code in Cocos2dxHelper. Someone tried a pull request with that before but it was never merged.

So I had to put it in Cocos2dxActivity

Kind Regards
Martell

I think onActivityResult is not called when login finished. But I have no clue why it’s not called yet…

I read the code once again, and I found that there was this line of code
Cocos2dxActivity.addOnActivityResultListener(this);

which then I got compile error can’t find Cocos2dxActivity when compiling the plugin

So what’s the correct way of listening to activityResult?

@siauw It’s been a while since I’ve looked at that code, and mine isn’t actually working right now either. The direction I remember taking is calling that addOnActivityResultListener with the plugin. Then in Cocos2dxActivity, you need to iterate over the list of ActivityResultListeners and do a separate call for each one. That code could be added into the main cocos2dx project, but when mine was working it was in my own activity.

@Martell I try to integrate IAP(Android Google) to the game but got a lots of error.
May u show me the proper way to integrate it.

@kslam212003 Have a look at IAPGooglePlay.java in this commit

This is exactly how you do it.

I was waiting for Cocos2dxHelper.java to be merged to cocos2d-x before I could fix this.
Those few line changes should fix your build errors.
I’ll do a PR to plugin-x with an update soon

I think I’ll pass on updating 169 files manually and wait for v3.1.2 or use Java on Android.
This must sound kinda dumb, but having never used github before I felt dumb when it asked for my card details. I assume you all assume everyone has a github account?

I never said you had to change 169 files?
I said you only have to change IAPGooglePlay.java by looking at this PR.

3.1.2 won’t fix this as this is part of plugin-x not cocos2d-x which is a separate project.

No you do not need card details for a github account unless you are paying for provate repos