B4A Class Twitter4J

Hi all ,

Finally I got it working with B4A . The class is included with the attached example.

I know it is not the fanciest example or class you would see but at least it is working and you are welcome to improve it (especially error handling :) I was just trying to make it work ) .
Also I just added setStatus function but it should be very easy to add all other functions - I hope so .

Download Twitter4J and copy JARs to Libraries folder
You also need Threading Library
Add your ConsumerKey and ConsumerSecret to the project : Create your own app here .

Also if I am doing anything wrong please let me know .


Finally I have a question : This library needs threading almost for every function at least those I tested . Is it OK to add a thread for every function or is there any other better way ?



Update 23DEC2015 :
New Example ‫‫Twitter4JMediaNewAuthorization.zip : Modified with pin code Authorization .


Update : New version Twitter4JMedia.zip
Modified Authentication as it seems that old one is not working .
Added a method to tweet with media (Tested a .png picture ).
 

Attachments

  • ‫‫Twitter4J.zip
    3 KB · Views: 276
  • ‫‫Twitter4JMedia.zip
    25.1 KB · Views: 230
  • ‫‫Twitter4JMediaNewAuthorization.zip
    25.2 KB · Views: 247
Last edited:

Chelu

Member
Licensed User
Longtime User
How can I upload a image with this class?
There isn't any method to do it.
You could add this functionality?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
How can I upload a image with this class?
There isn't any method to do it.
You could add this functionality?

If I have some time I will try to add tweet with image but meanwhile if you want to add any method you can check Twitter4J library documentation .
 

Chelu

Member
Licensed User
Longtime User
Thanks !!!
I will checkt it this night.
I'll tell you whether it is working or not.
 

Chelu

Member
Licensed User
Longtime User
I do not know what happened, but I retested a few weeks ago and no longer seems to work at all.
I think the problem is authentication. Now "oauth_verifier" is no longer returned under any circumstances.
I reinstalled the app, but can not get it to work.
I even changed the function:
B4X:
Sub web_PageFinished (Url As String)
    Log ("en PageFinished, url: " & Url)
    If Url.Contains("oauth_verifier") Then
        'get access using verifier
        Dim verifie As String=Url.SubString(Url.IndexOf("oauth_verifier")+15)
        Log("verifier:" & verifie)
        t.GetAccessToken(verifie)
    else if Url.contains ("oauth_token") Then
        Dim verifie As String=Url.SubString(Url.IndexOf("oauth_token")+12)
        Log("token:" & verifie)
        t.GetAccessToken(verifie)

    End If

End Sub
But although gives no error when posting've never published anything captured and error messages is always the same: "Exception: null"
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I do not know what happened, but I retested a few weeks ago and no longer seems to work at all.
I think the problem is authentication. Now "oauth_verifier" is no longer returned under any circumstances.
I reinstalled the app, but can not get it to work.
I even changed the function:
B4X:
Sub web_PageFinished (Url As String)
    Log ("en PageFinished, url: " & Url)
    If Url.Contains("oauth_verifier") Then
        'get access using verifier
        Dim verifie As String=Url.SubString(Url.IndexOf("oauth_verifier")+15)
        Log("verifier:" & verifie)
        t.GetAccessToken(verifie)
    else if Url.contains ("oauth_token") Then
        Dim verifie As String=Url.SubString(Url.IndexOf("oauth_token")+12)
        Log("token:" & verifie)
        t.GetAccessToken(verifie)

    End If

End Sub
But although gives no error when posting've never published anything captured and error messages is always the same: "Exception: null"

Please check the new example Twitter4JMediaNewAuthorization.zip attached to first post .
 

techknight

Well-Known Member
Licensed User
Longtime User
Must be doing something wrong. Copied the twitter4J into Libraries, but the sample is complaining about not being able to find pom.xml And its not showing up in the libraries list.

However, pom.xml is in the libraries folder!

Please advise?
 

techknight

Well-Known Member
Licensed User
Longtime User
Something on my end...

But I went in, did the Authorize, and it says Sub Tweetmedia not found and crashes.

Edit: Eventually that quit happening, and now its working. Go figure?

anyways... I changed it from tweetmedia to just tweet, and the MediaSent function doesnt fire to re-enable the command button.

Looking in the Twitter class, its not immediately obvious to me how to make that work with just tweet?
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Something on my end...

But I went in, did the Authorize, and it says Sub Tweetmedia not found and crashes.

Edit: Eventually that quit happening, and now its working. Go figure?

anyways... I changed it from tweetmedia to just tweet, and the MediaSent function doesnt fire to re-enable the command button.

Looking in the Twitter class, its not immediately obvious to me how to make that work with just tweet?

This one has a TweetSent event for text tweet .
Please download and check
 

Attachments

  • ‫‫Twitter4JMedia.zip
    30.6 KB · Views: 186

Steven Bacchioni

Member
Licensed User
Longtime User
Hi,

When I run your sample app, what needs to be entered into the edittext box to the left of the "Authorize" button?

I have my Conkey and ConSecret set with my account details.
 

karyadi

Member
Licensed User
Longtime User
Hi,
i try Twitter4JMediaNewAuthorization.zip but it cannot connect to twitter, just white blank on webview
i already fill my Conkey and ConSecret set with my account details.
what happen?
 

karyadi

Member
Licensed User
Longtime User
Hi, sorry i have try sample Twitter4JMediaNewAuthorization.zip, it must run in release not in debug and i can authorize, but the screen to fast
so i can not see the authorize key. how i can get authorize key by automatically ?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi, sorry i have try sample Twitter4JMediaNewAuthorization.zip, it must run in release not in debug and i can authorize, but the screen to fast
so i can not see the authorize key. how i can get authorize key by automatically ?
Sorry I am very busy .
Can you please check this version ?
It might have not-working methods

B4X:
        dim twitter as SMMTwitter4J
               twitter.Initialize("twitter",conKey,conSecret)
           
        twitter.getAuthenticationURL(conKey,conSecret)


Events
B4X:
Sub twitter_url(url As String)
    'load user login url
    web.LoadUrl(url)
End Sub

B4X:
Sub twitter_token(token As List)
       'token.get(0) is token
       'token.get(1) is token secret
End Sub

Sorry for a not clean wrapper .I was just writing it for myself to create a very simple B4J twitter app :D
Not sure it will work with B4A .
 

Attachments

  • SMMTwitter4J.zip
    336.1 KB · Views: 178

JohnC

Expert
Licensed User
Longtime User
I want to make a simple twitter app that simply displays my twitter feed - I will not be doing any tweets.

Does anyone know if this code still works?

I ask because of these issues:
1) Did twitter change it's API since 2016?
2) Is twitters api working after all the changes Musk did back in January?
 
Top