2014-01-06 62 views
2

我意識到,針對Android的Tumblr APi Jumblr沒有很好地記錄在我們如何實際執行一個。我已經在我的應用上成功授權我的帳戶。就這樣。據Jumblr的README https://github.com/tumblr/jumblr,你所要做的就是Android-Tumblr API - 適用於Android的Jumblr [OAuthConnectionException]

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

其中消費者密鑰和祕密在我的應用程序和組oauth_token和token_secret已經設置由用戶登錄時in.However,我是應用了得到的錯誤如

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

歡迎來到SO。日誌是否提供更多信息? – mikedidthis

+0

@mikedidthis:感謝您的評論。我已經解決了這個問題:D – user3159780

+0

非常好。如果解決方案是值得的,也許將它作爲其他人學習的答案? – mikedidthis

回答

2

我找到了解決方案,它適用於我。使用AsyncTask。謝謝!

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

}

+0

嗨,我使用上面的代碼,但它不工作,它提供了一個沒有找到類的錯誤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):\t at com.tumblr.jumblr.request.RequestBuilder.setConsumer(RequestBuilder.java:120) – Anshul