user3159780
user3159780

Reputation: 41

Android-Tumblr API - Jumblr for Android [OAuthConnectionException]

I realized that Jumblr, a Tumblr APi for Android isn't well documented on how do we actually go about implementing one. I've successfully authorize my account on my app. That's all. According to Jumblr's README https://github.com/tumblr/jumblr, all you have to do is to

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

where consumer key and secret is already set in my app and oauth_token and token_secret is got by the app when user logs in.However, I'm getting errors like

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

Upvotes: 2

Views: 1795

Answers (2)

user3679445
user3679445

Reputation: 11

Create a user token from following link: https://api.tumblr.com/console/calls/user/info

You can use client.setToken("oauth_token","oauth_token_secret");

Upvotes: 0

user3159780
user3159780

Reputation: 41

I found the solution.It works for me. Use AsyncTask. Thanks!

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

}

Upvotes: 2

Related Questions