Photos can not be shared via twitter -SDKBox - Social Sharing Plugin

I use sdkbox -Social Sharing plugin to share photos to twitter.
But none of them appear. This is my code. Can you help me? Thanks you before.

buttontwitter->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){
	switch (type)
	{
	case ui::Widget::TouchEventType::BEGAN:
		#if  CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
		      utils::captureScreen(CC_CALLBACK_2(HelloWorld::afterCaptured, this), "image.png");
		      sdkbox::SocialShareInfo info;
		      info.text = "Sdkbox";
		      info.image = linkfilephoto;
		      info.showDialog = flase;
		      info.platform = sdkbox::SocialPlatform::Platform_Twitter;
		      sdkbox::PluginShare::share(info);                                                                         
                #endif
		       break;
	}
});

and HelloWorld::afterCaptured

void HelloWorld::afterCaptured(bool succeed, const std::string &outputFile)
{
if (succeed) {
	linkfilephoto = outputFile;
}
else
{
	CCLOG("Capture screen failed.");
}
}

You should refactor this as the screen capture may not be complete before you try to use it. Personally, I’m not sure how async it is and how long capturing the screen could take, so that may not be the issue. By the way that the capture screenshot function has a callback for when it’s completed, I’m guessing it isn’t instantaneous.

Regardless I’d say that when the twitterbutton is pressed, you should capture the screen contents. Then, in the callback afterCapture(), if it was successful you should share the screenshot, otherwise you could either fallback to sharing some text or show an alert dialog to say that sharing failed.

You should not be calling the sharing code in the same place as capturing the screenshot, as currently you have no idea if the image object contains data or if it was successful or not.

Some quick pseudocode would be:

button->addTouchEventListener() {
    captureScreenShot(withAmazingCallback:, andImageName:)
    // DO NOT SHARE THE SCREENSHOT HERE!
}

...

void amazingCallback(success, output) {
    if success {
        // share image here instead!
    } else {
        // fallback to text, or show error alert
    }
}

I’m also unsure on how the CC_CALLBACK_2 callbacks work, so also ensure that your callback is being called correctly and image data is being received.

Hope that helps :slight_smile:

can you explain more about AmazingCallback.
I have seached but in Cocos2dx there is no AmazingCallback.

The pseudocode I gave above is exactly that: pseudocode. I was rather tired last night, hence I didn’t type in any code for you, the pseudocode is there to simply guide you in changing your own code.

To put it simply:

  1. Move the sharing code from where you capture the screenshot (the button touch listener) to where you receive the results of the screenshot capture (the callback you showed in your example).
  2. If the screenshot was successful, share it. Otherwise, fallback to just text or nothing at all.
  3. Ensure your callback gets called correctly with the right parameters.
  4. If the screenshot function says it’s failing every time, your problem is with the function or potentially the callback, although you should investigate that if the refactoring does not work.

Screen capture is successful. I tried adding the capture image and succeeded. But when sharing via twitter is not.
I will try using EziSocial. But this plugin has been deleted.
What do you have solution to share image via twitter?
Thank you !!

take a look at this

Thank you very much. This is used and not effective. Only text and urls can be shared. Can not share photo.
I use Android

I really need to share screenshot of the game score through twitter. Everybody help me.

Can you try leave the link section empty and see if it shares?

if you want to share screenshot, you need follow permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

you can use sdkbox-sample-share try again.