微博,更新状态 [英] twitter,update status

查看:91
本文介绍了微博,更新状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是Twitter的整合,通过twitter4j.I到Android能够成功地读取贴由我THT鸣叫。

Hi i am integrating twitter to android through twitter4j.I can successfully read tht tweets posted by me.

现在我amtrying从它。但是我不能发布的tweet。

Now i amtrying to posting tweet from it.but i cant.

我正奇怪的警告如下:

    02-01 16:28:43.298: WARN/System.err(729): 401:Authentication credentials were missing or incorrect.
02-01 16:28:43.308: WARN/System.err(729): {"request":"\/1\/statuses\/update.json","error":"Read-only application cannot POST"}
02-01 16:28:43.308: WARN/System.err(729): TwitterException{exceptionCode=[15bb6564-00e54a7f], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.7-SNAPSHOT(build: fd76317d18a608269f0566f73bbb827420c4c77e)}
02-01 16:28:43.308: WARN/System.err(729):     at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:309)
02-01 16:28:43.318: WARN/System.err(729):     at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:72)
02-01 16:28:43.318: WARN/System.err(729):     at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:103)
02-01 16:28:43.318: WARN/System.err(729):     at twitter4j.Twitter.updateStatus(Twitter.java:501)
02-01 16:28:43.330: WARN/System.err(729):     at com.T4J_OAuth.activities.Main$1.onClick(Main.java:69)
02-01 16:28:43.330: WARN/System.err(729):     at android.view.View.performClick(View.java:2364)
02-01 16:28:43.330: WARN/System.err(729):     at android.view.View.onTouchEvent(View.java:4179)
02-01 16:28:43.339: WARN/System.err(729):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
02-01 16:28:43.339: WARN/System.err(729):     at android.view.View.dispatchTouchEvent(View.java:3709)
02-01 16:28:43.339: WARN/System.err(729):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 16:28:43.349: WARN/System.err(729):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 16:28:43.349: WARN/System.err(729):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 16:28:43.349: WARN/System.err(729):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 16:28:43.359: WARN/System.err(729):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
02-01 16:28:43.359: WARN/System.err(729):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
02-01 16:28:43.359: WARN/System.err(729):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
02-01 16:28:43.369: WARN/System.err(729):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
02-01 16:28:43.369: WARN/System.err(729):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
02-01 16:28:43.378: WARN/System.err(729):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 16:28:43.378: WARN/System.err(729):     at android.os.Looper.loop(Looper.java:123)
02-01 16:28:43.378: WARN/System.err(729):     at android.app.ActivityThread.main(ActivityThread.java:4363)
02-01 16:28:43.378: WARN/System.err(729):     at java.lang.reflect.Method.invokeNative(Native Method)
02-01 16:28:43.389: WARN/System.err(729):     at java.lang.reflect.Method.invoke(Method.java:521)
02-01 16:28:43.389: WARN/System.err(729):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-01 16:28:43.398: WARN/System.err(729):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-01 16:28:43.398: WARN/System.err(729):     at dalvik.system.NativeStart.main(Native Method)


虽然我已经把我的Twitter应用程序的读取和写入,它说我可以用只读的应用程序tpost。


though i have set my application in twitter as read and write ,it says me can tpost by read only app.

请帮我整理出来

推荐答案

在twitter上发布推文比获得时间表不同。

Posting a tweet on twitter is different than getting the timeline.

考虑Twitter4J考虑的方案可能会以下内容:

Taking Twitter4J into account the scenarios may be following:

这需要你有被授权微博类的一个实例。

It requires you to have an instance of Twitter class which is authorised.

您做以下,以获得时间线:

You do following in order to get the timeline:

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
RequestToken requestToken = twitter.getOAuthRequestToken(CALLBACKURL); 
...
...

在成功的OAuth验证,你得到的 oauth_verifier 变量,然后创建一个 AccessToken 与下面几行:

After successful OAuth verification, you get the oauth_verifier variable, and then create an AccessToken with the following lines:

AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,oauth_verifier);
String token = accessToken.getToken(), 
      secret = accessToken.getTokenSecret();

除上述标记秘密的地方,它会生成使用的 AccessToken 之后。

Save the above token and secret somewhere, it will be used in generating the AccessToken later.

现在,在code更新状态:

Now, the code to update status:

AccessToken accessToken = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey,consumerSecret,accessToken);
Status status = twitter.updateStatus("My First Status Update");
statusId = (int)status.getId();

这将更新消息我的第一个状态更新来你的时间表,将获得 ID 在此状态在 statusId 变量。

This will update the message My First Status Update to your timeline and will get the ID of this status in the statusId variable.

有关如何使用OAuth实现登录与Twitter,让你的时间轴的第一鸣叫的工作示例,请点击链接到我的博客文章。

For a working example of how to use OAuth to implement sign-in with twitter and get the first tweet of your timeline, click this link to my blog post.

我相信稍微修改成和使用上述code在它之后,你可以把它变成一个鸣叫张贴code呢!

I am sure that after a slight modification into that and the use of above code in it, you can transform it into a tweet posting code too!

这篇关于微博,更新状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆