Error with imageuri on sending tweet

android

#1

Hi,

I’ve just integrated twitter with my Android app, and the login works fine. However I’ve a problem with sending a tweet.

Code is

Uri myImageUri = Uri.parse("file:///android_asset/twitterimg.jpg");
final Card card = new Card.AppCardBuilder(this)
		  .imageUri(myImageUri)
		  .googlePlayId("com.example.mygame")
		  .build();

final TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();

final Intent intent = new ComposerActivity.Builder(this)
	    .session(session)
	    .card(card)
	    .createIntent();
	startActivity(intent);

When the tweet is sent it gets the error ‘com.twitter.sdk.android.core.TwitterApiException: /android_asset/twitterimg.jpg (No such file or directory)’ - however the image is shown in the app when they enter their tweet text, so it’s definitely exists on the device in the right place, and I presume specified ok in the intent. Last thing I tried was making sure the image was the right size (with preferred aspect ratio) as described in https://docs.fabric.io/android/twitter/compose-tweets.html but no change.

Exception is:

11-02 17:16:05.805: E/TweetUploadService(4237): Post Tweet failed
11-02 17:16:05.805: E/TweetUploadService(4237): com.twitter.sdk.android.core.TwitterApiException: /android_asset/twitterimg.jpg (No such file or directory)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:390)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
11-02 17:16:05.805: E/TweetUploadService(4237): 	at java.lang.Thread.run(Thread.java:1027)

#2

Hey @BlissfulGames,

It seems like the image can’t be found at the time of the posting. Is any code moving it another location? As a test, if you switch to uploading an image from a hard-code url, does that work?

-Mike


#3

Hi Mike,

Nothing should be happening to the image file - it just sits in the Assets folder.

How do you mean a hard-code URL? When I initially tried it I assumed the file had to be available online and so my original uri was pointing to an http:// file on my website, but when that didn’t work I read the docs a bit more carefully and saw it was supposed to be a local file. It’s a cocos2d-x game and most of the images are in the Assets folder rather than than the Android resources folder (/res/drawable say).

Nik


#4

I’ve just seen a stackoverflow post (http://stackoverflow.com/questions/32092189/fabric-twitterkit-compose-tweet-with-image-from-asset-folder) that says the file has to be somewhere like the SD card since it needs to be accessible by other apps (the twitter say). Is that right?

It would be awkward as I didn’t want to a) pollute the user’s storage, or b) have additional permissions (I’ll need the android.permission.WRITE_EXTERNAL_STORAGE permission). Really it’s the text they’re tweeting that’s important rather than the image (in fact since it’s a google play link I was hoping the card would be automatically created from the link)


#5

Thanks @BlissfulGames, the hard-coded URL was intended as a test to see if it was working via that way or not.

Are you actually looking to include an image in addition to the text or do you just want a Twitter card created with the tweet?


#6

Just the twitter card I think. The idea is that the user is sharing the game with other people, so they can write whatever they like, but a link to google play is important.

After integrating twitter into the app using Fabric it sent to me to the documentation here: https://docs.fabric.io/android/twitter/compose-tweets.html and the 2nd option of twitterkit sounded very simple plus ticked all the boxes. The image isn’t really important, but I think it didn’t compile if I didn’t include the image URI (edit - wasn’t a compile error, it was a runtime exception: IllegalStateException App Card requires a non-null imageUri)


#7