I am trying to integrate the Facebook into my game developed in C++ for iPhone and Android using Cocos2d-x. I couldn't find any good API for that in C++. Can anyone help on how to do this?
Asked
Active
Viewed 3,021 times
2
-
1Use Objective-C instead. Not for your game of course, but obviously you have to use objective-C to display things to the screen in iOS so you don't need to have a C++ API for Facebook. – borrrden Jul 26 '12 at 07:09
-
I'm using cocos2d-x for development. That is I need to run the code in android also. – Aaron Jul 26 '12 at 07:12
2 Answers
4
I did not know about the iPhone but in Android i have done using the JNI call to java and from java i have called the facebook api,please check below code.
in $COCOS2DX_HOME\cocos2dx\platform\android CCApplication.h
void postMsgOnFacebook1(char *msg);
void CCApplication::postMsgOnFacebook(char *msg){
CCApplication.cpp
void CCApplication::postMsgOnFacebook(char *msg){
JniMethodInfo minfo;
if(JniHelper::getStaticMethodInfo(minfo,
"org/cocos2dx/lib/Cocos2dxHelper",
"postMsgOnFacebook",
"(Ljava/lang/String;)V"))
{
jstring StringArg1 = minfo.env->NewStringUTF(msg);
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, StringArg1);
minfo.env->DeleteLocalRef(StringArg1);
minfo.env->DeleteLocalRef(minfo.classID);
}
}
in java org.cocos2dx.lib.Cocos2dxHelper add new method
public static void postMsgOnFacebook(final String msg) {
//facebook posting code here
}
after this change please clean and build project on any button click in game
CCApplication::sharedApplication()->postMsgOnFacebook((char *)"facebook post");
i have done this in cocos2d-2.0-x-2.0.4. if you need more help then please let me know
Thank you.

Sameer Z.
- 3,265
- 9
- 48
- 72
-
which SDK or API we have to link to eclips project for this? can u guide for that? – Komal Shah Aug 27 '13 at 08:01