Twitter Library

alwaysbusy

Expert
Licensed User
Longtime User
This is a library to use Twitter functionality in b4a with oAuth authentication. The library is a little bigger than is allowed on this forum, but you can download it from

http://www.gorgeousapps.com/ABTwitter.zip

To use this library you need to do the following steps:

1. If you do not have one, make a twitter account
2. Go to Twitter to add your app to twitter
3. Fill in the fields on the website (See attachment Twitter1.jpg)
4. Note the consumer key and consumer secret (See attachemt Twitter2.jpg) You'll need them later in your code.

How does it work

By using the consumer key, consumer secret, a token and a token secret you can connect to a twitter account.

To get the token en token secret you can add the following snippet:

B4X:
' replace the codes by your consumer key an consumer secret generated on the twitter page
Dim Ret as Boolean
Ret = myABTwitter.ABConnect("DfNWSCNc1TaTpcsDcMPK", "Y0gYdZFdX78HmoybH1fLRkX6rbySxdxm8iRqpv14A", "", "")
If myABTwitter.ABURL <> "" Then
     Dim p As PhoneIntents
     StartActivity(p.OpenBrowser(myABTwitter.ABURL)) 
End If

The user is directed to the twitter website to login.
After login in, the user receives a PIN code.

He can now enter this PIN code into your app, and then rerun the ABConnect function, but now with the ABtoken and ABtoken secret:

B4X:
myABTwitter.ABEnterPIN(editText1.Text)
Ret = myABTwitter.ABConnect("DfNWSCNc1TaTpcsDcMPK", "Y0gYdZFdX78HmoybH1fLRkX6rbySxdxm8iRqpv14A", myABTwitter.ABToken , myABTwitter.ABTokenSecret)

It is best to save the ABToken and ABtokenSecret on the device, so the user only has to do this once.

The next time the app is running, just read the saved Token and TokenSecret and run the following snippet (using your codes):

B4X:
Ret = myABTwitter.ABConnect("DfNWSCNc1TaTpcsDcMPK", "Y0gYdZFdX78HmoybH1fLRkX6rbySxdxm8iRqpv14A", Token, TokenSecret)

A litte demo app is attached to show you some basic tasks like getting your tweets and sending a tweet, but there are many more functionalities.

Do not forget to change the Consumer Key and Consumer Secret if you create a new app!
 

Attachments

  • Twitter1.jpg
    Twitter1.jpg
    91.8 KB · Views: 507
  • Twitter2.jpg
    Twitter2.jpg
    70.2 KB · Views: 465
  • ABTwitterTest.zip
    7.1 KB · Views: 819

bluedude

Well-Known Member
Licensed User
Longtime User
Cool except for one thing

Hi,

I think this is cool but there is one thing not so cool, the sample code would expose the application consumer and secret.

It is really easy to view the code in an .apk and this sample would anyone allow to see your app. keys.

Any developer could exploit this by letting their app. use the keys of your app.

Either you need to encrypt them or get them online from a database by using a HTTP request. Preferrable through an SSL connection.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Keys

Yep,

Using encryption would be a way to solve it. For the rest, thanks for this great lib.!
 

hasanaydin52

Member
Licensed User
Longtime User
message is not going

Hello Alwaysbusy,

Thank you for library,

I was registering the my program, i was get consumer and consumer secret,
i changed within three code lines.

it was connect, i can get followers and friends.

when sending message ABURL return null, ret return false.

My followers can not see my messages.
 
Last edited:

adex1

Member
Licensed User
Longtime User
Twitter have change their policy on 3rd party apps early this year.
 

Alex Ventura

Member
Licensed User
Longtime User
help with ABTwitter

Do you know how can I get the time of the posted tweet? I'm trying with ABTwitter but I can't...
 

geola

Member
Licensed User
Longtime User
Hello,

is the ABTwitter LIB still working?
Based on the example I got an error at ABConnect
"the request is understood but has been refused..."
"SSL is required"

Thanks,

geola
 

alienhunter

Active Member
Licensed User
Longtime User
Hello,

is the ABTwitter LIB still working?
Based on the example I got an error at ABConnect
"the request is understood but has been refused..."
"SSL is required"

Thanks,

geola

same here ... would have been nice to have something , there is no twitter library
working anymore ,except what Erel posted , but there is no login implemented which
i do not have time :oops:
 
Top