【问题标题】:Android-Tumblr API - Jumblr for Android [OAuthConnectionException]Android-Tumblr API - 适用于 Android 的 Jumblr [OAuthConnectionException]
【发布时间】:2014-01-06 13:22:11
【问题描述】:

我意识到 Jumblr,一个适用于 Android 的 Tumblr API 并没有很好地记录我们如何实际实施一个。我已成功在我的应用上授权我的帐户。就这样。根据 Jumblr 的 README https://github.com/tumblr/jumblr,你所要做的就是

 JumblrClient client = new JumblrClient("consumer_key","consumer_secret");
 client.setToken("oauth_toke n", "oauth_token_secret");

在我的应用程序中已经设置了消费者密钥和秘密,并且 oauth_token 和 token_secret 在用户登录时由应用程序获取。但是,我遇到了类似的错误

org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.Full logcat:

【问题讨论】:

  • 欢迎来到 SO。日志是否提供更多信息?
  • @mikedidthis:感谢您的评论。我已经解决了这个问题:D
  • 优秀。如果解决方案值得,也许将其发布为其他人学习的答案?

标签: android oauth tumblr


【解决方案1】:

我找到了解决方案。它对我有用。使用异步任务。谢谢!

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ExportDatabaseCSVTask t=new ExportDatabaseCSVTask();
    t.execute("");


}

public class ExportDatabaseCSVTask extends AsyncTask<String, Void, Boolean>
 { 
    private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
    User user;
    JumblrClient client;
    String a,b,c;
    int d,e;
    @Override
    protected void onPreExecute() 
    { 
        this.dialog.setMessage("Exporting Info...");
        this.dialog.show();

         client = new JumblrClient("consumer_key","consumer_secret");
         client.setToken("oauth_token","oauth_token_secret");

    }

    protected Boolean doInBackground(final String... args)
    {

        user = client.user();
        // Make the request  
        a =  user.getName();
        b = user.getDefaultPostFormat();  
        c = user.toString();  
        d= user.getFollowingCount();  
        e = user.getLikeCount();  

        List<Blog> blogs = client.userFollowing();
        for (Blog blog : blogs) {
            Log.e("USER","1"+blog.getTitle());
        }

        TextPost post;
        try {
            post = client.newPost(client.user().getName(), TextPost.class);
            post.setTitle("title");
            post.setBody("body");
            post.save();
        } catch (IllegalAccessException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }



        return true;
    } 

    @Override
    protected void onPostExecute(final Boolean success) 
    {
        if (this.dialog.isShowing())
        {
            this.dialog.dismiss();
        } 

        if(success )
        {
            Log.e("USER", "" + a);  
              Log.e("USER", "" +b);  
              Log.e("USER", "" + c);  
              Log.e("USER", "" + d);  
              Log.e("USER", "" + e);  

        }




    }
} 

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

【讨论】:

  • 嗨,我正在使用上面的代码,但它不起作用,它给出了找不到类的错误 04-23 10:36:34.606: E/AndroidRuntime(847): java.lang.NoClassDefFoundError: org.scribe.builder.api.TumblrApi 04-23 10:36:34.606: E/AndroidRuntime(847): at com.tumblr.jumblr.request.RequestBuilder.setConsumer(RequestBuilder.java:120)
【解决方案2】:

从以下链接创建用户令牌: https://api.tumblr.com/console/calls/user/info

你可以使用 client.setToken("oauth_token","oauth_token_secret");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 2012-08-30
    相关资源
    最近更新 更多