[TUT] Sending a Tweet

Tutorials with advanced 'difficulty' and more Lines of Code.

[TUT] Sending a Tweet

Postby blundell » Sun Jul 24, 2011 6:54 pm

Ok What we are going to do:

Authorise your app to use a users twitter account.
Send a tweet from this account.

Workflow:

User presses Login Button
Checks if user has logged in before
Twitter webpage is opened
User logins in to twitter
App is then allowed to post tweets
Users presses Tweet Button
Tweet is sent to Twitter
Simple!

Have a read on my blog:

http://blog.blundell-apps.com/sending-a-tweet/

If you find this helpful please say thanks :-) Happy Coding

And any questions just ask!
Attachments
tweetToTwitterS3.png
Tweet!
tweetToTwitterS3.png (36.27 KiB) Viewed 6214 times
tweetToTwitterS2.png
Twitter log in
tweetToTwitterS2.png (69.78 KiB) Viewed 6214 times
tweetToTwitters1.png
App first loaded
tweetToTwitters1.png (31.14 KiB) Viewed 6214 times
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Re: [TUT] Sending a Tweet

Postby sandhuyoo » Mon Sep 05, 2011 9:18 am

Hi Blundell,

you post is good But when I am trying to use your code to implement in my app it crashes becoz of the callback URL
in your code its "tweet-to-twitter-blundell-01-android:///" I just want to knw that is this callback URL and how can I set this callback URL for my App.

Please reply soon..

and thanks for uploading your project.. it works fine when I simply imported it to my work space.. but its giving issues when I am trying to implement in my app..


Thanks In advance
Gurvinder Singh Sandhu
sandhuyoo
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 05, 2011 9:12 am

Re: [TUT] Sending a Tweet

Postby blundell » Mon Sep 05, 2011 1:19 pm

When creating your own project you will have to change it in your manifest.

Check out the application tag in the manifest, specifically the intent filter and the data item. Change this to the url you are attempting.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Sending a Tweet

Postby sandhuyoo » Tue Sep 06, 2011 5:33 am

Thanks for Reply,

Actually I dont knw what to give the value in the data tag, you have given this
"<data android:scheme="tweet-to-twitter-blundell-01-android" />"
but I dont knw what value should I give :( I am new to android thats why I dont knw.

If you can please help me what to give the value here..

Thanks In Advance
Gurvinder
sandhuyoo
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 05, 2011 9:12 am

Re: [TUT] Sending a Tweet

Postby blundell » Tue Sep 06, 2011 12:02 pm

You can have whatever you want as long as it's unique, and it has to match the CALLBACK_URL variable in the TweetToTwitterActivity.java class.

Maybe "tweet-to-twitter-sandhuyoo-01-android" will do :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Sending a Tweet

Postby sandhuyoo » Tue Sep 06, 2011 2:07 pm

I have used the same you typed.. :) but its my bad that is not working at all :(

it opens a browser and a page not found error comes up..

I am really screwed with this twitter integration :(
sandhuyoo
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 05, 2011 9:12 am

Top

Re: [TUT] Sending a Tweet

Postby blundell » Tue Sep 06, 2011 11:22 pm

I still think the problem is in your manifest, please check it against the tutorial. Your app should be picking up the url through an intent filter and redirecting back inside your app, instead of trying to load it in the browser.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Sending a Tweet

Postby sandhuyoo » Wed Sep 07, 2011 6:14 am

<activity android:name="ShareOnTwitter" android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tweet-to-twitter-sandhuyoo-01-android"/>

</intent-filter>
</activity>

this is my manifest file code for Share On twitter.. its not my main activity.. i guess the tutorial has only this diff that in tutorial it was the main activity.. mine is not.. rest is the same..
sandhuyoo
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 05, 2011 9:12 am

Re: [TUT] Sending a Tweet

Postby blundell » Wed Sep 07, 2011 12:17 pm

Hmm all I can think of is, have you created the twitter app correctly on the twitter site? Also have you copied the consumer key .. etc correctly into the Java class.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Sending a Tweet

Postby Klick » Thu Sep 22, 2011 6:11 pm

Thank you for the great tutorial. It was the only one out of half a dozen I could get to work. I am at the stage where I am about to release the app to the general public, but one line of your script is concerning me.

It is this line
Code: Select all
private static final String CONSUMER_SECRET = "yourConsumerSecret"; // XXX Encode in your app


How exactly am I supposed to encode the secret key provided by Twitter?
Thanks for any advice.
Klick
Freshman
Freshman
 
Posts: 4
Joined: Sat Sep 17, 2011 2:38 pm

Re: [TUT] Sending a Tweet

Postby blundell » Thu Sep 22, 2011 8:25 pm

Well if you use proguard this will worry about it for you?

Otherwise maybe look at base64 encoding: http://www.wikihow.com/Encode-a-String- ... -With-Java

You can have a read of this it might help explain: http://stackoverflow.com/questions/4427 ... 32#4427432

Otherwise I wouldn't worry about it too much :-) know one is going to be malicious towards you until you play with the big boys.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

`

Postby Klick » Thu Sep 22, 2011 9:28 pm

Thank you for your fast and detailed response. I may not be playing with the big boys, but it would take just the one rouge user.

Also I am trying to import your original package into mine now I have yours working. I have this import and this line of code but keep getting this error. Do you have any advice.
Code: Select all
import com.blundell.tut.ttt.TweetToTwitterActivity;


Code: Select all
TweetToTwitterActivity.ButtonLogin();


The method ButtonLogin() is undefined for the type TweetToTwitterActivity


EDIT:

I resolved that issue. My ill understanding and the lack of ButtonLogin method didn't help things. I did however have a buttonLogin method. I'm not used to such a strict langauge in regards to upper and lowercase.

I currently have this working with the previous import statement I posted.

Code: Select all
               TweetToTwitterActivity twitter = new TweetToTwitterActivity();
               twitter.buttonLogin(v);


However now I am receiving a NullPointerException pointing to this line of the twitter package.
Code: Select all
if (mPrefs.contains(PREF_ACCESS_TOKEN)) {


I think again I am missing something obvious and any help would be great. Cheers
Klick
Freshman
Freshman
 
Posts: 4
Joined: Sat Sep 17, 2011 2:38 pm

Re: [TUT] Sending a Tweet

Postby Klick » Fri Sep 23, 2011 2:06 pm

Again I have been able to solve that issue. I have realised that it is because I need to pass a context through to the twitter class.

This is causing me all kinds of headaches. If you have any advice on an easier approach that would be useful. Again thank you for creating a well documented script.
Klick
Freshman
Freshman
 
Posts: 4
Joined: Sat Sep 17, 2011 2:38 pm

Re: [TUT] Sending a Tweet

Postby alpar.torok » Fri Oct 07, 2011 1:18 pm

Hello... thanks for the great tut. Tried it, used it, it all worked really nice but now on the authentification screen when the text field is tapped the virtual keyboard doesn't appear. Have you encountered this isssue?
alpar.torok
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Oct 07, 2011 1:14 pm

Re: [TUT] Sending a Tweet

Postby blundell » Tue Oct 18, 2011 12:52 pm

Nope sorry never seen an issue with the keyboard, is this on the login screen? Make sure you don't have windowSoftInputMode or other xml tags overridden in your manifest.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
Next

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests