join the conversation! twitter is your go-to social networking app and the source for what's happening in the world. from world news to local news, entertainment to sports and gaming, politics to fun stories that go viral, when it happens in the world, it happens on twitter first. find friends or follow influential people - every voice can impact the world! join over 2 billion users worldwide!
tweet, retweet, reply to tweets, share or like - twitter is easy to use
chat privately or go big and initiate a group conversation with anyone who follows you. track your friends & other twitter followers or follow your favorite celebrity alongside hundreds of interesting twitter users, to read their content at a glance. engage your social network with noteworthy links, photos and videos. discover which of your tweets were liked or retweeted.
create your free twitter account today!
twitter allows you to find interesting people or build a following of people who are interested in you. maintaining a social connection has never been easier!twitter allows celebs to build a personal connection with their fans. this is why twitter has become one of the most used social media platforms in the world.
build an engaging profile
customize your profile, add a photo, description, location, and background photo
tweet often and optimize your posting times
post visual content
use hashtags in your tweets
draw in followers outside of twitter
know what’s trending now
discover top trending hashtags and breaking news headlines. whether you’re interested in sports highlights, pop culture and entertainment or politics, twitter is your source of information.
live streaming events
join the conversation or watch live videos to deeply engage with large audiences directly from your mobile device. go live, create your own live streaming events, share videos or sit back and watch events from around the world.
privacy policy: twitter /en/privacy
terms and conditions: twitter /en/tos
原文: www blogs /and_he/archive/2011/05/23/2054494.html
转载留在以后参考~~
关于twitter这一块,自发这篇博文之后有很多人问我,有的验证成功了不跳转,或者其它原因什么的,我看了一下,这篇博文里面有写呀,下面以红色粗体文字注明一下
刚进公司,叫我先学习twitter和facebook,就类似于国内的微博,或者分享功能,点击某个按钮,出来一个提示框,可以分享到某些地方,这里实现的就是分享到twitter,当然得要使用代理,因为这是给老外做的,所以得符合他们的习惯
先说一下实现的功能吧,首先运行的时候,会检查是否登陆twitter(通过sharedpreference文件保存登陆状态),如果没有登陆的话会跳转到twitter的登陆认证页面,提示用户输入用户名和密码,这些就是oauth认证的步骤,不懂的看这儿 www blogs /and_he/archive/2011/05/22/2053477.html
做过新浪微博的都应该知道,首先要申请成为开发者,创建自己的应用,然后会给你一些比如consumer key和consumer secret之类的东西,这些东西要先记下来,代码里面要用到的,其余的不啰嗦了,只是要注意一点,创建twitter应用的时候造成不能忘了填那个callback url,我当初就没填,结果整了几天都整不出来结果,也算是我的一点经验吧,下面贴代码,以便于以后查阅
首先我们要用到twitter封闭好的一些包,这里用到两个twitter4j-core-android和twitter4j-media-support-android,百度一下就出来了
以下是工程目录结构
package
com.twitter;
public
class
const {
public
static
final
string consumer_key
=
"
ifkj4coaz9f9ngfoe1lfuq
"
;
public
static
final
string consumer_secret
=
"
hn2nfe4mtl7oqjauirwfrnk9xkhywg2vzmaj6afwfj8
"
;
public
static
final
string request_token_url
=
"
api.twitter /oauth/request_token
"
;
public
static
final
string access_token_url
=
"
api.twitter /oauth/access_token
"
;
public
static
final
string callback_url
=
"
api.twitter /oauth/authorize
"
;
public
static
final
string twitpic_api_key
=
"
a77709ebb6c51de0e77f723751a5f9a4
"
; }
下面是twitter类(主类)
package
com.twitter;
import
java.io.ioexception;
import
java.io.inputstream;
import
twitter4j.twitterfactory;
import
twitter4j.conf.configurationbuilder;
import
android.app.activity;
import
android.app.progressdialog;
import
android.content.context;
import
android.content.intent;
import
android.content.sharedpreferences;
import
android.content.res.assetmanager;
import
android.os.asynctask;
import
android.os.bundle;
import
android.text.editable;
import
android.text.textwatcher;
import
android.util.log;
import
android.view.view;
import
android.view.window;
import
android.view.view.onclicklistener;
import
android.widget.button;
import
android.widget.edittext;
import
android.widget.textview;
import
android.widget.toast;
public
class
extends
activity { edittext et_content;
//
评论内容
edittext et_des;
//
图片描述
textview tv_num;
//
剩余字数
button btn_send;
//
发送按钮
int
num
=
140
;
//
定义总字数
progressdialog progressdialog;
//
当点击发送的时候显示此进度条
sharedpreferences spf; twitterconnect tc;
//
定义一个twitter连接对象
boolean
connectionstatus
=
false
;
//
定义当前的连接状态为false
string content; string describle; @override
public
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.twitter); tc
=
new
twitterconnect(
this
); spf
=
getsharedpreferences(
"
bravesoft
"
, context.mode_private); et_content
=
(edittext) findviewbyid(r.id.et_content); et_des
=
(edittext) findviewbyid(r.id.et_des); tv_num
=
(textview) findviewbyid(r.id.tv_num); tv_num.settext(
"
140
"
); progressdialog
=
new
progressdialog(
this
); progressdialog.settitle(
"
正在发送...
"
); progressdialog.setmessage(
"
正在发送,请稍候...
"
); et_content.addtextchangedlistener(
new
textwatcher() {
private
charsequence temp;
private
int
selectionstart;
private
int
selectionend; @override
public
void
ontextchanged(charsequence s,
int
start,
int
before,
int
count) { temp
=
s;
//
显示当前输入框中的所有内容
} @override
public
void
beforetextchanged(charsequence s,
int
start,
int
count,
int
after) { } @override
public
void
aftertextchanged(editable s) {
int
number
=
num
-
s.length(); tv_num.settext(
""
number); selectionstart
=
et_content.getselectionstart(); selectionend
=
et_content.getselectionend();
if
(temp.length()
>
num) { s.delete(selectionstart
-
1
, selectionend);
int
tempselection
=
selectionstart; et_content.settext(s); et_content.setselection(tempselection);
//
设置光标在最后
} } }); btn_send
=
(button) findviewbyid(r.id.btn_send); connectionstatus
=
spf.getboolean(
"
connection_tatus
"
,
false
); btn_send.setonclicklistener(
new
onclicklistener() { @override
public
void
onclick(view v) { content
=
et_content.gettext().tostring();
//
得到评论内容
describle
=
et_des.gettext().tostring();
//
得到图片描述内容
if
(connectionstatus) {
//
如果用户处于登陆状态,获取用户头像跟name
progressdialog.show(); getuserinfotask getuserinfotask
=
new
getuserinfotask(); getuserinfotask.execute(
""
); } } });
if
(
!
connectionstatus) { btn_send.setenabled(
false
); sendmessage(); } }
/**
* 如果用户处于登陆状态,获取用户头像跟name * *
@author
administrator *
*/
class
getuserinfotask
extends
asynctask
<
string, integer, string
>
{ @override
protected
string doinbackground(string... params) { string result
=
""
; configurationbuilder confbuild
=
new
configurationbuilder(); confbuild.setoauthconsumerkey(const.consumer_key); confbuild.setoauthconsumersecret(const.consumer_secret); confbuild.setoauthaccesstoken(spf.getstring(
"
oauth_token
"
,
""
)); confbuild.setoauthaccesstokensecret(spf.getstring(
"
oauth_token_secret
"
,
""
)); twitter4j.conf.configuration config
=
confbuild.build();
if
(twitterconnect.twitter
!=
null
) twitterconnect.twitter.shutdown(); twitterconnect.twitter
=
new
twitterfactory(config).getinstance(); inputstream input
=
null
;
try
{ twitterconnect.accesstoken
=
twitterconnect.twitter .getoauthaccesstoken();
boolean
btest
=
false
; assetmanager am
=
getassets();
try
{ input
=
am.open(
"
btn_dokusya_toukou.png
"
); }
catch
(ioexception e) { e.printstacktrace(); }
if
(tc
==
null
) { tc
=
new
twitterconnect(twitter.
this
); } btest
=
tc.twittercontribute(content, input, describle);
if
(btest) { result
=
"
ok
"
; }
else
{ result
=
"
failure
"
; } }
catch
(exception e) { }
return
result; } @override
protected
void
onpostexecute(string result) {
super
.onpostexecute(result);
if
(progressdialog.isshowing()) { progressdialog.dismiss(); }
if
(result.equals(
"
ok
"
)) { toast.maketext(twitter.
this
,
"
发送成功
"
, toast.length_long).show(); }
else
{ toast.maketext(twitter.
this
,
"
发送失败
"
, toast.length_long).show(); } } }
public
void
sendmessage() {
new
send().start(); }
class
send
extends
thread { @override
public
void
run() {
super
.run();
try
{ thread.sleep(
3000
); }
catch
(interruptedexception e) { e.printstacktrace(); } intent intent
=
new
intent(twitter.
this
, twitterloginbrowser.
class
); startactivityforresult(intent,
1
); } } @override
protected
void
onactivityresult(
int
requestcode,
int
resultcode, intent data) {
super
.onactivityresult(requestcode, resultcode, data);
if
(requestcode
==
1
) {
if
(resultcode
==
1
) {
//
表示从twitterloginbrowser返回
connectionstatus
=
spf.getboolean(
"
connection_tatus
"
,
false
);
if
(connectionstatus) { btn_send.setenabled(
true
); } } } } }
twitterconnect类
package
com.twitter;
import
java.io.ioexception;
import
java.io.inputstream;
import
java .url;
import
twitter4j.status;
import
twitter4j.twitter;
import
twitter4j.twitterexception;
import
twitter4j.twitterfactory;
import
twitter4j.auth.accesstoken;
import
twitter4j.auth.requesttoken;
import
twitter4j.conf.configuration;
import
twitter4j.conf.configurationbuilder;
import
twitter4j.media.imageupload;
import
twitter4j.media.imageuploadfactory;
import
twitter4j.media.mediaprovider;
import
android.content.context;
import
android.graphics.bitmap;
import
android.graphics.bitmapfactory;
public
class
twitterconnect { context context;
public
static
twitter twitter;
public
static
requesttoken requesttoken;
public
static
accesstoken accesstoken;
public
twitterconnect(context context) {
this
.context
=
context; twitter
=
new
twitterfactory().getinstance(); }
public
string twitterloginoauth() { twitter.setoauthconsumer(const.consumer_key, const.consumer_secret);
try
{ requesttoken
=
twitter.getoauthrequesttoken();
return
requesttoken.getauthentication
"
&force_login=true
"
; }
catch
(twitterexception e) { e.printstacktrace();
return
"
baidu
"
; }
//
已经得到临时访问令牌
//
request token=7hmpofnr5ev1kjcw036mdi1hpvycbb1srkkk3r6ax30
//
request token secret=fahibfx04lbqhme392hth1lgl8hqxm2p0ij5kzlofk
//
url=
api.twitter /oauth/authenticate?oauth_token=svrksiu1arj7h24rvhphennzfxqliebry7uefydmb9k
}
//
得到用户名
public
string getusername() {
try
{
return
twitter.showuser(accesstoken.getuserid()).getname(); }
catch
(exception e) {
return
""
; } }
//
得到用户头像
public
bitmap getuserimage(string userimageurl) { bitmap image
=
null
;
try
{ url url
=
new
; image
=
bitmapfactory.decodestream(url.openstream()); }
catch
(exception e) { e.printstacktrace(); }
return
image; }
/**
* *
@param
text * 评论内容 *
@param
input * 图片的一个inputstream *
@param
description * 图片描述 *
@return
*/
public
boolean
twittercontribute(string text, inputstream input, string description) {
boolean
isok
=
false
; configuration config
=
null
; imageupload uploads
=
null
;
try
{ status status
=
null
;
if
(input
!=
null
) {
if
(config
==
null
) { configurationbuilder confbuild
=
new
configurationbuilder(); confbuild.setoauthconsumerkey(const.consumer_key); confbuild.setoauthconsumersecret(const.consumer_secret); confbuild.setoauthaccesstoken(accesstoken.gettoken()); confbuild.setoauthaccesstokensecret(accesstoken .gettokensecret()); confbuild.setmediaproviderapikey(const.twitpic_api_key);
//
发送图片和对图片的描述
config
=
confbuild.build(); uploads
=
new
imageuploadfactory(config) .getinstance(mediaprovider.twitpic); } string uploadre
=
""
; uploadre
=
uploads.upload(
"
"
, input, description); system.out.println(
"
uploadre
"
uploadre);
if
(input
!=
null
)
try
{ input.close(); }
catch
(ioexception e) { }
if
(
!
uploadre.equals(
""
)) { status
=
twitter.updatestatus(text
"
"
uploadre); system.out.println(
"
uploadre=
"
uploadre); } }
else
{ status
=
twitter.updatestatus(text); }
if
(status
!=
null
) { system.out.println(
"
发表内容:
"
status.gettext()); isok
=
true
; } }
catch
(exception e) { isok
=
false
; }
return
isok; } }
twitterloginbrowser类
package
com.twitter;
import
twitter4j.twitterexception;
import
android.app.activity;
import
android.app.progressdialog;
import
android.content.context;
import
android.content.intent;
import
android.content.sharedpreferences;
import
android.content.sharedpreferences.editor;
import
android.graphics.bitmap;
import
android.os.asynctask;
import
android.os.bundle;
import
android.view.keyevent;
import
android.view.window;
import
android.webkit.webchromeclient;
import
android.webkit.webview;
import
android.webkit.webviewclient;
import
android.widget.toast;
public
class
twitterloginbrowser
extends
activity { webview webview; progressdialog progressdialog;
//
定义一个进度条
twitterconnect tc; string authenticateurl
=
""
; connecttask task; string oauthtoken; string oauthverifier; bitmap userimage;
//
用户头像
@override
protected
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.twitter_loginbrowser); progressdialog
=
new
progressdialog(twitterloginbrowser.
this
); progressdialog.settitle(
"
请等待
"
); progressdialog.setmessage(
"
正在加载页面,请稍等...
"
); progressdialog.show();
//
启动的时候就让它显示
webview
=
(webview) findviewbyid(r.id.webview); webview.getsettings().setjavascriptenabled(
true
); webview.requestfocus(); tc
=
new
twitterconnect(
this
); task
=
new
connecttask(
this
); task.execute(
"
login
"
);
//
执行载入页面任务
webview.setwebviewclient(
new
webviewclient() { @override
public
boolean
shouldoverrideurlloading(webview view, string url) { view.load;
return
true
; } @override
public
void
onpagestarted(webview view, string url, bitmap favicon) {
super
.onpagestarted(view, url, favicon); system.out.println(
"
开始加载页面:
"
url); }
//
页面载入完成
@override
public
void
onpagefinished(webview view, string url) {
super
.onpagefinished(view, url);
//
url=
api.twitter /oauth/authorize?oauth_token=9kpqny7vhmywc5nrxf2eq73zn4vkxjqcgzj62sizu
&oauth_verifier=3b7fbas9xoyh8i3qeqrfguqjlgmufqh5fzmz7j3ws
toast.maketext(twitterloginbrowser.
this
,
"
页面加载完成
"
, toast.length_long).show();
if
(url
!=
null
&&
url.startswith(const.callback_url)) { string[] param
=
url.split(
"
\\?
"
)[
1
].split(
"
&
"
);
if
(param[
0
].startswith(
"
oauth_token
"
)) { oauthtoken
=
param[
0
].split(
"
=
"
)[
1
]; }
else
if
(param[
1
].startswith(
"
oauth_token
"
)) { oauthtoken
=
param[
1
].split(
"
=
"
)[
1
]; }
if
(param[
0
].startswith(
"
oauth_verifier
"
)) { oauthverifier
=
param[
0
].split(
"
=
"
)[
1
]; }
else
if
(param[
1
].startswith(
"
oauth_verifier
"
)) { oauthverifier
=
param[
1
].split(
"
=
"
)[
1
]; } system.out.println(
"
oauthtoken=
"
oauthtoken); system.out.println(
"
oauthverifier=
"
oauthverifier);
try
{ twitterconnect.accesstoken
=
twitterconnect.twitter .getoauthaccesstoken( twitterconnect.requesttoken, oauthverifier); webtask wt
=
new
webtask(); wt.execute(
""
); }
catch
(twitterexception e) { e.printstacktrace(); system.out.println(
"
发生错误了
"
); } } } }); webview.setwebchromeclient(
new
webchromeclient() {
//
控制进度条的显示
@override
public
void
onprogresschanged(webview view,
int
newprogress) {
super
.onprogresschanged(view, newprogress);
if
(newprogress
!=
100
) {
if
(
!
progressdialog.isshowing()) { progressdialog.show(); } }
else
{
if
(progressdialog.isshowing()) { progressdialog.dismiss(); } } } }); }
//
获取用户名和头像
class
webtask
extends
asynctask
<
string, integer, string
>
{ @override
protected
string doinbackground(string... params) { string result
=
""
;
if
(oauthtoken
!=
null
&&
oauthverifier
!=
null
) { system.out.println(
"
开始获取用户名和头像
"
); string userimageurl
=
""
;
//
用户头像url
try
{ userimageurl
=
twitterconnect.twitter .showuser(twitterconnect.accesstoken.getuserid()) .getprofileimage.tostring(); }
catch
(twitterexception e) { e.printstacktrace(); } string username
=
tc.getusername();
if
(userimage
!=
null
) { userimage.recycle(); } userimage
=
tc.getuserimage(userimageurl);
//
登陆成功 回到来的画面
intent intent
=
new
intent(); bundle bundle
=
new
bundle(); bundle.putparcelable(
"
userimage
"
, userimage); bundle.putstring(
"
username
"
, username); intent.putextra(
"
userinfo
"
, bundle);
//
保存登陆状态
sharedpreferences spf
=
getsharedpreferences(
"
bravesoft
"
, context.mode_private); editor editor
=
spf.edit(); editor.putstring(
"
oauth_token
"
, twitterconnect.accesstoken.gettoken()); editor.putstring(
"
oauth_token_secret
"
, twitterconnect.accesstoken.gettokensecret()); editor.putboolean(
"
connection_tatus
"
,
true
); editor.putstring(
"
username
"
, username); editor.putstring(
"
userimgurl
"
, userimageurl); editor mit(); twitterloginbrowser.
this
.setresult(
1
, intent); bundle.clear(); result
=
"
ok
"
; }
return
result; } @override
protected
void
onpostexecute(string result) {
super
.onpostexecute(result);
if
(result.equals(
"
ok
"
)) { toast.maketext(twitterloginbrowser.
this
,
"
登陆成功
"
, toast.length_long).show(); }
else
{ toast.maketext(twitterloginbrowser.
this
,
"
登陆失败
"
, toast.length_long).show(); }
//
twitterloginbrowser.this.finish();
} }
class
connecttask
extends
asynctask
<
string, integer, string
>
{
public
connecttask(context context) { } @override
protected
string doinbackground(string... params) { authenticateurl
=
tc.twitterloginoauth();
return
authenticateurl; } @override
protected
void
onpostexecute(string result) {
super
.onpostexecute(result);
if
(
!
result.equals(
""
)) { webview.load;
//
载入网页
}
else
{ toast.maketext(twitterloginbrowser.
this
,
"
载入错误,请重试
"
, toast.length_long).show(); twitterloginbrowser.
this
.finish(); } } } @override
public
boolean
onkeydown(
int
keycode, keyevent event) {
if
(keycode
==
keyevent.keycode_back
&&
webview.cangoback()) { webview.goback();
return
true
; }
return
super
.onkeydown(keycode, event); } }
twitterrific mac版是一款非常现代化优秀的桌面twitter客户端,这款软件不仅看起来惊人,它的表现也是非常棒的,本文给大家的带来了如何下载twitter数据副本的教程。教程如下 在 iphone 或 ipad 上打开“twitter”。(您也可以使用 twitter 网站) 点击左上角的个人资料图标开始。接下来,选择“设置和隐私”,如下面的屏幕截图所示。在设置菜单中,点击“帐户”以进一步操作。现在,点击“数据和权限”下的“您的 twitter 数据”以继续进行数据请求。这将在您的浏览器中打开 twitter。如果您尚未登录,系统会要求您输入登录凭据。点击“下载您的数据档案”以从 twitter 请求您的数据。现在您只需点击“请求数据”选项并等待 twitter 向您连接的电子邮件帐户发送电子邮件。 收到来自 twitter 的电子邮件后,您可以返回相同的设置菜单并选择“下载数据”部分下的“下载数据”选项。 您从 twitter 下载的数据将是一个 zip 文件。因此,您需要先使用“文件”应用解压缩此压缩文件, 然后才能实际查看所有数据。 twitter客户端 ?twitter客户端twitterrific ?twitterific已经被重新设想成为mac最友好,最强大和最现代的twitter客户端。twitterrific for mac使twitter变得有趣。 ?twitterrific for mac你的方式 - 一个干净,整洁的时间表,只是你关心的内容,推特是按照时间顺序呈现的,其他人的喜好则不在你的时间轴上。 ?专为macos设计 - twitterrific mac感觉就像在mac上的家一样,支持通知中心,retina显示,内置共享,美丽的动画,全屏模式,等等。 ?时间轴嘉豪 - 控制你的微博与多个时间轴窗口从同一个帐户或多个帐户,所有这一切都组织在您的mac的桌面上。 ?完全可访问性 - 浏览时间表,撰写推文,甚至可以使用voice over快速轻 松地添加图像描述。 ?风格 - twitterrific mac的外观面板支持主题,让你自定义字体和字体大小,甚至可以让你控制媒体如何出现在时间轴上。 ?随处读取 - 无论您在iphone,ipad或其他mac上使用twitterrific mac,该应用程序都会自动同步您的阅读位置,以获得无缝的twitter体验。
还没有评论,来说两句吧...