在这里,我将一些文本从Android应用程序发布到用户的Twitter帐户,并且具有ConsumerKey,Consumer密钥,Accesstoken和Accesstoken密钥.
https://API.twitter.com/1.1/statuses/update.Json
通过使用简单的http客户端请求,我想在Twitter用户帐户上发布数据.我怎样才能做到这一点?
我尝试了类似的东西
httpClIEnt httpclIEnt = new DefaulthttpClIEnt();httpPost httppost = new httpPost("http://API.twitter.com/1/statuses/update.Json");// httpPost httppost = new httpPost("https://graph.facebook.com/" + profile_ID + "/Feed");System.out.println("httppost " + httppost);try { // Add your data List<nameValuePair> nameValuePairs = new ArrayList<nameValuePair>(2); nameValuePairs.add(new BasicnameValuePair("access_token", access_token_value)); nameValuePairs.add(new BasicnameValuePair("message", compose.getText().toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute http Post Request httpResponse response = httpclIEnt.execute(httppost); System.out.println("response "+response.toString());}catch (ClIEntProtocolException e) { // Todo auto-generated catch block}catch (IOException e) { // Todo auto-generated catch block}
但是参数在我的代码following this中是错误的,但是我没有得到它,那么对此有什么合适的解决方案?
解决方法:
由于您正在询问如何使用REST API 1.1从AndroID应用程序发布消息,因此我建议您使用Twitter 4j库,以便将Twitter集成到您的AndroID应用程序中.
该库在内部封装了身份验证功能(通过OAuth库)和其他重要功能.以下是其一些功能:
Twitter4J具有以下特点:
> 100%纯Java-适用于任何Java Platform版本5或更高版本
> AndroID平台和Google App Engine就绪
>零依赖性:不需要其他JAR文件
>内置的OAuth支持
>开箱即用的gzip支持
> 100%兼容Twitter API 1.1
您需要通过此库调用简单功能,以使用有关Twitter的特定功能.这是一个演示此库用法的链接:
http://twitter4j.org/en/code-examples.html
您可以在链接http://twitter4j.org/上下载此库.
这是使用库https://github.com/itog/Twitter4j-android-Sample实现的示例.
总结以上是内存溢出为你收集整理的如何使用REST API 1.1从Android应用程序发布消息全部内容,希望文章能够帮你解决如何使用REST API 1.1从Android应用程序发布消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)