Android Twitter 应用程序 - 不起作用

发布于 2024-11-10 03:42:56 字数 922 浏览 0 评论 0原文

哇,我一直在尝试让一个简单的 Android Twitter 应用程序运行起来,但这是不可能的。我有 iOS 背景。我目前正在尝试使这些工作:

  1. 来自 Marakana 的 MyTwitter 应用程序。 http://marakana.com/forums/android/examples/312.html

  2. Marakana 简单 OAuth 演示。 https://github.com/marakana/OAuthDemo

  3. Twitter4j 示例 itog_lab。 https://github.com/itog/Twitter4j-android-Sample

  4. AndroidTwitterSample 。 http://www.android10 .org/index.php/articleslibraries/291-twitter-integration-in-your-android-application#josc329

我总是收到未经授权的错误,无法请求访问令牌。有人有过这样的经历吗?

Wow, Ive been trying to get a simple Android Twitter app to work but its been impossible. I come from an iOS background. Im currently trying to make these work:

  1. MyTwitter app from Marakana. http://marakana.com/forums/android/examples/312.html

  2. Marakana Simple OAuth demo. https://github.com/marakana/OAuthDemo

  3. Twitter4j Sample itog_lab. https://github.com/itog/Twitter4j-android-Sample

  4. AndroidTwitterSample. http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application#josc329

I always get unauthorized error unable to request access token. Has anyone had this experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯角 2024-11-17 03:42:56

如果您满足于使用 Intent 调用 Twitter(这意味着您需要已安装的 Twitter 应用程序才能正常工作),您可以通过以下方式访问 Twitter:

try{
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final List<?> activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
    for (int i = 0; i < len; i++) {
        final ResolveInfo app = (ResolveInfo) activityList.get(i);
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
            final ActivityInfo activity=app.activityInfo;
            final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
            intent=new Intent(Intent.ACTION_SEND);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.setComponent(name);
            intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
            startActivity(intent);
            break;
        }
    }
} catch(final ActivityNotFoundException e) {
    Log.i("Twitter intent", "no twitter native", e );
}

If you are content with calling Twitter using Intent (meaning that you will need the Twitter app already installed for this to work), you can access Twitter with something like this:

try{
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final List<?> activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
    for (int i = 0; i < len; i++) {
        final ResolveInfo app = (ResolveInfo) activityList.get(i);
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
            final ActivityInfo activity=app.activityInfo;
            final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
            intent=new Intent(Intent.ACTION_SEND);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.setComponent(name);
            intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
            startActivity(intent);
            break;
        }
    }
} catch(final ActivityNotFoundException e) {
    Log.i("Twitter intent", "no twitter native", e );
}
酒与心事 2024-11-17 03:42:56

我的示例有效 http://schwiz.net/blog/2011/using-scribe -with-android/ 如果您遇到麻烦,请联系我。

my example works http://schwiz.net/blog/2011/using-scribe-with-android/ ping me if you run into trouble.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文