I´m developing a game in cocosd2-x since 2 month. I know that post scores on twitter or facebook is important, and i wan to implement it. Someone know if exist a extension or singleton structure to do it? I have tried, but is not easy or fast, it will take me a lot of time to get a good structure. I have been looking for in internet, and i get:
String tweetUrl = "https://twitter.com/intent/tweet?text=Hello ! I have just got " + score + " points in mygame for Android !!!!";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
You simply can’t AFAIK implement FB an Twitter in your app both for iOS and Android together
You should use something like:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
//android part code here
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
//iOS part code here
#endif
I develop also for iOS and Android both, but things like FB, Twitter, OpenFeint you must do separately (especially that to implement it on Android you sould use JNI to connect with Java part).
Cheers,
Barti
I think it could be possible, i took a look to http://code.google.com/p/facebook-cpp-graph-api/, and i think is using HTTP to validate the session, and store the keys and token in the cpp code.
I have been some problems with calls from C++ to Java, i followed your tutorial, but i get an exception trying to call a post in facebook’s wall. I’m working on it.
Actually just work on iOS. No in Android, but facebook libraries are linked on the project and close to work ^^.
Hi ,
I am also facing some problems with the calls from C*+ to Java.
If you got some solution please share it .
Pipero Man wrote:
Hi Barti.
>
I have been some problems with calls from C*+ to Java, i followed your tutorial, but i get an exception trying to call a post in facebook’s wall. I’m working on it.
>
Actually just work on iOS. No in Android, but facebook libraries are linked on the project and close to work ^^.
>
This is the code:
> https://github.com/Piperoman/CCSocialNetwork
>
If someone can help us to fix it… he will be welcome.
If not, don’t worry, i will fix it some day.
Actually I am new to cocos2dx and i also want to do facebook integration which will work for both android and ios.
For ios , i know the way but for android i dont no anything.
I searched for it and found out that i need to use JNI for calling functionality from java to c++ code but i am not able to find a good tutorial for it.
If you have done the integration with both of them so please guide me how to do that .
Pipero Man wrote:
What is your problem? I cannot help you if you don´t explain it!
>
The code works on my computer, to run the project you must put all the data correctly to compile.
Open eclipse and make new Android project with existing code.
Browse your project and open it .
I added the facebook lib.
Classes folder doesnt have the classes into it so i linked all the classes from that folder.
There is no error so i tried to compiled it and was successfully able to do that .
It ran on the device , i was able to see the screen where there are 3 options i.e. mail,twitter and fb.
I clicked on FB and it crashed.
Sorry for explaining in that detail but i am very new to this platform and want to know what i did wrong .
I check the Android.mk file , the paths are correct.
Error i got is :
10-06 01:46:25.797: E/AndroidRuntime(9947): FATAL EXCEPTION: GLThread 11
10-06 01:46:25.797: E/AndroidRuntime(9947): java.lang.ExceptionInInitializerError
10-06 01:46:25.797: E/AndroidRuntime(9947): at com.facebook.android.Facebook.autoPublishAsync(Facebook.java:1049)
10-06 01:46:25.797: E/AndroidRuntime(9947): at com.facebook.android.Facebook.authorize(Facebook.java:222)
10-06 01:46:25.797: E/AndroidRuntime(9947): at com.facebook.android.Facebook.authorize(Facebook.java:147)
10-06 01:46:25.797: E/AndroidRuntime(9947): at tutorial.getsocial.meizpipero.FacebookConnector.login(FacebookConnector.java:42)
10-06 01:46:25.797: E/AndroidRuntime(9947): at tutorial.getsocial.meizpipero.GetSocial.postMessage(GetSocial.java:201)
10-06 01:46:25.797: E/AndroidRuntime(9947): at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesEnd(Native Method)
10-06 01:46:25.797: E/AndroidRuntime(9947): at org.cocos2dx.lib.Cocos2dxRenderer.handleActionUp(Cocos2dxRenderer.java:79)
10-06 01:46:25.797: E/AndroidRuntime(9947): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$10.run(Cocos2dxGLSurfaceView.java:348)
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1295)
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
10-06 01:46:25.797: E/AndroidRuntime(9947): Caused by: java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.os.Handler.(Handler.java:121)
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.os.AsyncTask$InternalHandler.(AsyncTask.java:421)
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.os.AsyncTask$InternalHandler.(AsyncTask.java:421)
10-06 01:46:25.797: E/AndroidRuntime(9947): at android.os.AsyncTask.(AsyncTask.java:152)
10-06 01:46:25.797: E/AndroidRuntime(9947): … 10 more
Pipero Man wrote:
Just do a clone from https://github.com/Piperoman/CCSocialNetwork
>
Change the path of the makefile to compile and try it working.
>
Then just take a look to the code to see how to do C++ call to java.
>
It is difficult to do because there are not tutorials…. I hope this example can help you. If you have a problem just ask.
Im not sure what is the problem, so i gonna explain to you the steps y follow.
1º Clone the project.
2º Compile using $PATH/GetSocial/proj.android/build_native.sh ; Must be correct
3º Open eclipse and IMPORT the project located on $PATH/Getsocial/proj.android
4º Open Facebook Libraries on $PATH/facebook-facebook-android-sdk-525f851
5º Add Path Facebook, both projects must be open
6º Run the project.
If all this steps are OK, then, you maybe must configure paths on projects. I can´t help without more info. Its important that you uncomment all CCLogs to see on ADB LOGCAT where the code is failing.
Report what Logs do you see and what logs you don´t, and i will help you to correct the problem.
Sorry for troubling you again but i followed all the steps you explained above but still its crashing when i click on share the on fb.
Actually email and twitter is working fine but there is some problem with fb.
Is post functionality is in GetSocial.java class??
Shall i try to modify it ??
Logs are
@
10-06 02:59:14.105: W/apk path(11609): /data/app/tutorial.getsocial.meizpipero-1.apk
10-06 02:59:14.125: D/cocos2d-x debug info(11609): Java_tutorial_getsocial_meizpipero_GetSocial_testCallFromJava
10-06 02:59:21.965: D/cocos2d-x debug info(11609): HelloWorld: try to send an email
10-06 02:59:21.965: D/cocos2d-x debug info(11609): Static postMessageEMail
10-06 02:59:21.965: D/cocos2d-x debug info(11609): Status: 0
10-06 02:59:21.965: D/cocos2d-x debug info(11609): jClass Located?
10-06 02:59:21.965: D/cocos2d-x debug info(11609): mID: 1101587796
10-06 02:59:21.965: D/activity(11609): Send a email on Java
10-06 02:59:21.965: D/PhoneWindow(11609): couldn’t save which view has focus because the focused view org.cocos2dx.lib.Cocos2dxGLSurfaceView@44c68958 has no id.
10-06 02:59:21.965: D/cocos2d-x debug info(11609): Finish
10-06 02:59:25.915: D/cocos2d-x debug info(11609): HelloWorld: try to send a tweet
10-06 02:59:25.915: D/cocos2d-x debug info(11609): Static postMessageToTweet
10-06 02:59:25.915: D/cocos2d-x debug info(11609): Status: 0
10-06 02:59:25.915: D/cocos2d-x debug info(11609): jClass
10-06 02:59:25.915: D/cocos2d-x debug info(11609): mID: 1101587900
10-06 02:59:25.915: D/activity(11609): Tweet on Java
10-06 02:59:25.945: D/PhoneWindow(11609): couldn’t save which view has focus because the focused view org.cocos2dx.lib.Cocos2dxGLSurfaceView@44c68958 has no id.
10-06 02:59:25.945: D/cocos2d-x debug info(11609): Finish
10-06 02:59:30.565: D/cocos2d-x debug info(11609): HelloWorld: try to post on Facebook
10-06 02:59:30.565: D/cocos2d-x debug info(11609): Static postMessageToFB
10-06 02:59:30.565: D/cocos2d-x debug info(11609): Status: 0
10-06 02:59:30.565: D/cocos2d-x debug info(11609): jClass Located?
10-06 02:59:30.565: D/cocos2d-x debug info(11609): mID: 1101587692
10-06 02:59:30.565: D/activity(11609): postMessage (FB) on Java
10-06 02:59:30.565: W/dalvikvm(11609): Exception Ljava/lang/RuntimeException; thrown during Landroid/os/AsyncTask;.
10-06 02:59:30.565: D/cocos2d-x debug info(11609): Finish
10-06 02:59:30.575: W/dalvikvm(11609): threadid=10: thread exiting with uncaught exception (group=0x40020ac0)
10-06 02:59:30.585: E/AndroidRuntime(11609): FATAL EXCEPTION: GLThread 11
10-06 02:59:30.585: E/AndroidRuntime(11609): java.lang.ExceptionInInitializerError
10-06 02:59:30.585: E/AndroidRuntime(11609): at com.facebook.android.Facebook.autoPublishAsync(Facebook.java:1049)
10-06 02:59:30.585: E/AndroidRuntime(11609): at com.facebook.android.Facebook.authorize(Facebook.java:222)
10-06 02:59:30.585: E/AndroidRuntime(11609): at com.facebook.android.Facebook.authorize(Facebook.java:147)
10-06 02:59:30.585: E/AndroidRuntime(11609): at tutorial.getsocial.meizpipero.FacebookConnector.login(FacebookConnector.java:42)
10-06 02:59:30.585: E/AndroidRuntime(11609): at tutorial.getsocial.meizpipero.GetSocial.postMessage(GetSocial.java:201)
10-06 02:59:30.585: E/AndroidRuntime(11609): at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesEnd(Native Method)
10-06 02:59:30.585: E/AndroidRuntime(11609): at org.cocos2dx.lib.Cocos2dxRenderer.handleActionUp(Cocos2dxRenderer.java:79)
10-06 02:59:30.585: E/AndroidRuntime(11609): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$10.run(Cocos2dxGLSurfaceView.java:348)
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1295)
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
10-06 02:59:30.585: E/AndroidRuntime(11609): Caused by: java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.os.Handler.(Handler.java:121)
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.os.AsyncTask$InternalHandler.(AsyncTask.java:421)
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.os.AsyncTask$InternalHandler.(AsyncTask.java:421)
10-06 02:59:30.585: E/AndroidRuntime(11609): at android.os.AsyncTask.(AsyncTask.java:152)
10-06 02:59:30.585: E/AndroidRuntime(11609): … 10 more
@
Pipero Man wrote:
Im not sure what is the problem, so i gonna explain to you the steps y follow.
>
1º Clone the project.
2º Compile using $PATH/GetSocial/proj.android/build_native.sh ; Must be correct
3º Open eclipse and IMPORT the project located on $PATH/Getsocial/proj.android
4º Open Facebook Libraries on $PATH/facebook-facebook-android-sdk-525f851
5º Add Path Facebook, both projects must be open
6º Run the project.
>
If all this steps are OK, then, you maybe must configure paths on projects. I can´t help without more info. Its important that you uncomment all CCLogs to see on ADB LOGCAT where the code is failing.
>
Report what Logs do you see and what logs you don´t, and i will help you to correct the problem.