Introduction
Used SocialApi classes:
The samples archive contains:
1. Add following code to your manifest:
2. Add following directives to your project's main file:
3. Select the SocialApi library from the list of the available libraries in the IDE. Declare a TwitterProvider and a SocialApiActivity object in Sub Process_Globals and Sub Globals respectively
4. Call the TwitterProvider.SetActivity method in your Sub Activity_Resume in order to bind the TwitterProvider instance to the current activity passing the name of the event that will be raised every time the TwitterProvider session changes.
5. Create your event with the name that you have previously set
6. Create the login/logout handlers. The login and logout actions are performed asynchronously
8. Do something and evaluate the result
Done! Now we have to setup our app in our Twitter developer dashboard.
Setup our app in Twitter developer dashboard
Follow the steps described here:
http://azure.microsoft.com/en-us/do...vices-how-to-register-twitter-authentication/
Done! You are ready to go!
Useful links
Please test and post any feedback, questions, comments you may have!
That's all for now folks!~
Version history until SocialApi 2.3
2.3
Used SocialApi classes:
- TwitterProvider: A non activity object that must be declared in any Sub Process_Globals.
- SocialApiActivity: An activity object that can be only declared in a Sub Globals and is used to bind a TwitterProvider object to an activity through the TwitterProvider.SetActivity method.
- Download the latest socialapi package, extract it anywhere on your hard disk and note the folder name.
- Copy the wrapper files (jar + xml) in the socialapi folder into your B4A Libraries folder.
- Each sample in the socialapi\twitter\samples folder has AdditionalRes and AdditionalJar directives that have to be changed. Change the C:\b4a-dev folder to where you have extracted the socialapi archive.
The samples archive contains:
- Sample1: Quick start sample that can be used as a bare-bone template for your new apps
1. Add following code to your manifest:
B4X:
AddApplicationText(
<activity
android:name="com.datasteam.twitter.android.TwitterActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>)
2. Add following directives to your project's main file:
B4X:
#AdditionalRes: <your-installation-folder>\socialapi\twitter\sdk\res
#AdditionalJar: <your-installation-folder>\socialapi\twitter\sdk\twittersdk.jar
3. Select the SocialApi library from the list of the available libraries in the IDE. Declare a TwitterProvider and a SocialApiActivity object in Sub Process_Globals and Sub Globals respectively
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Twitter As TwitterProvider
Twitter.Initialize("<your-consumer-key>", "<your_consumer_secret> ")
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ThisActivity As SocialApiActivity
End Sub
4. Call the TwitterProvider.SetActivity method in your Sub Activity_Resume in order to bind the TwitterProvider instance to the current activity passing the name of the event that will be raised every time the TwitterProvider session changes.
B4X:
Sub Activity_Resume
Twitter.SetActivity(ThisActivity.Initialize("twitter"))
End Sub
5. Create your event with the name that you have previously set
B4X:
Sub Twitter_Event (Provider as SocialApiProvider)
BtnConnect.Enabled = Not(Provider.Connected)
BtnDisconnect.Enabled = Provider.Connected
End Sub
Sub Twitter_Connected (Provider as SocialApiProvider)
Msgbox(Provider.Me, "!")
End Sub
Sub Twitter_Disconnected (Provider as SocialApiProvider)
Msgbox("Bye bye!", "JustDisconnected!")
End Sub
Sub Twitter_Failed (Provider as SocialApiProvider)
If Msgbox2("Failed to actualize your details."&CRLF&CRLF&"Retry?", "Error", "Yes", "No", "", Null) = DialogResponse.POSITIVE Then
Provider.Retry
End If
End Sub
6. Create the login/logout handlers. The login and logout actions are performed asynchronously
B4X:
Sub BtnConnect_Click
Twitter.Login(true)
End Sub
Sub BtnDisconnect_Click
Twitter.Logout
End Sub
8. Do something and evaluate the result
B4X:
Dim TweetDialog As InputDialog
If TweetDialog.Show("", "Your tweet", "Tweet!", "Cancel", "", Null) = DialogResponse.POSITIVE Then
If TweetDialog.Input <> "" Then
Dim Result As TwitterResult
Result = Twitter.Tweet(TweetDialog.Input)
If Result.Success Then
Msgbox(Result, "Tweet!")
End If
End If
End If
Done! Now we have to setup our app in our Twitter developer dashboard.
Setup our app in Twitter developer dashboard
Follow the steps described here:
http://azure.microsoft.com/en-us/do...vices-how-to-register-twitter-authentication/
Done! You are ready to go!
Useful links
- Best Android emulator: http://www.genymotion.com
- Cool Git Manager (windows): http://www.syntevo.com/smartgithg/
Please test and post any feedback, questions, comments you may have!
That's all for now folks!~
Version history until SocialApi 2.3
2.3
- Restructured again into a single package (socialapi) after finding out how to properly use the #AdditionalRes directive to avoid conflict with other b4a libraries
- Restructured due to a conflict with AdMod library and TwitterProvider has its own package
- Initial version
Attachments
Last edited: