Android Post Status to Twitter using Jtwitter- Example
来源:互联网 发布:阿里云备案邮寄 编辑:程序博客网 时间:2024/06/07 02:31
In android, we can able to post a status to twitter by using jtwitter. Its very simple to post a status in twitter. For that we need jtwitter.jar. you can download the jwitter.jar from here
Post Status in Twitter Example :-
Create a new android project,
Add the below code in your AndroidManifest.xml for internet permission
1
<
uses-permission
android:name
=
"android.permission.INTERNET"
/>
Now we need to add Jtwitter to our project. Download the jwitter and save it in local drive.
Click the Android Project –> Properties — > (In left Pane) Java Build Path — > Libraries
In Libraries Tab click the ‘Add External Jars’ Button and then add the Jtwitter jar file.
Edit your java file
01
package
org.androidpeople.twitter;
02
03
import
winterwell.jtwitter.Twitter;
04
import
winterwell.jtwitter.TwitterException;
05
import
android.app.Activity;
06
import
android.os.Bundle;
07
import
android.widget.Toast;
08
09
public
class
TwitterExample
extends
Activity {
10
11
Twitter twitter;
12
13
@Override
14
public
void
onCreate(Bundle savedInstanceState) {
15
super
.onCreate(savedInstanceState);
16
setContentView(R.layout.main);
17
18
// Set your Twitter username / Password
19
twitter =
new
Twitter(
"username"
,
"password"
);
20
21
try
22
{
23
//Status to post in Twitter
24
twitter.setStatus(
"This is my first Tweet from Android - AndroidPeople.com"
);
25
Toast.makeText(TwitterExample.
this
,
"Article Posted to Twitter Successfully!!"
, Toast.LENGTH_SHORT).show();
26
}
27
catch
(TwitterException.E401 e)
28
{
29
// comes here when username or password is wrongs
30
Toast.makeText(TwitterExample.
this
,
"Wrong Username or Password,Kindly Check your logins"
,Toast.LENGTH_SHORT).show();
31
}
32
catch
(Exception e)
33
{
34
Toast.makeText(TwitterExample.
this
,
"Network Host not responding"
,Toast.LENGTH_SHORT).show();
35
}
36
}
37
}
Now run the application.
The output will looks like
Download the full source code of Twitter Example from here
- Android Post Status to Twitter using Jtwitter- Example
- [IPhone] Post to Twitter
- 论文读书笔记-using twitter to recommend real-time topical news
- Twitter Typeahead plugin Example
- Redis Twitter Example
- The Classical Example using DOM to operate a XML File
- An example of using libexif to set JPEG Orientation Tag
- An example of using libexif to set JPEG Orientation Tag
- How to compile a dlib example using eclipse in windows?
- a complete example of using One to Many and One to One associations using MyBatis annotations
- Post a transaction and the appropriate status to the IDoc.
- Post a transaction and the appropriate status to the IDoc.
- Post a transaction and the appropriate status to the IDoc.
- tweepy(Twitter API) status object
- Using jQuery to POST [FromBody] parameters to Web API
- Using jQuery to POST [FromBody] parameters to Web API
- twitter crawler POST GET
- Appium_Automators' Cafe Appium android example program for windows using java
- Java编码问题
- C++内存问题(很多公司面试的题目,值得一看,看懂了别忘了告诉我)
- uiimage 變動圖像的大小
- 使用强类型数据集进行有效编码——转载
- C++ operator 重载
- Android Post Status to Twitter using Jtwitter- Example
- 秘方
- mysql 常用命令大全
- MyEclipse7.0 ibatis插件安装
- 青春
- jQuery AJAX回调函数this指向问题
- 我的FLASH情结2010——浅谈FLASH WEB GAME与创业
- 怎样用Visual Build工具搭建自己的Daily Build环境
- 80后的我们已经谈不起任何恋爱