开发者

Android Twitter App - none work

Wow, Ive been trying to get a simple Android Twitter app to 开发者_如何学Cwork 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?


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 );
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜