如何在android中将照片发布到tumblr?

时间:2012-12-24 06:50:26

标签: android share tumblr

我必须在按钮点击中将照片发布到“tumblr”。我尝试了以下方式与tumblr连接,但不幸的是我没有通过..!

我的回调网址是否正确。?我的回拨网址出现问题。

public class TumblrDemoActivity extends Activity {

private static final String TAG = "TumblrDemo";

private static final String REQUEST_TOKEN_URL = "https://www.tumblr.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "https://www.tumblr.com/oauth/access_token";
private static final String AUTH_URL = "https://www.tumblr.com/oauth/authorize";

// Taken from Tumblr app registration
private static final String CONSUMER_KEY = "MY_CONSUMER_KEY";
private static final String CONSUMER_SECRET = "MY_SECRET_KEY";
private static final String CALLBACK_URL = "tumblrdemo://tumblrdemo.com/ok";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // To get the oauth token after the user has granted permissions
    Uri uri = this.getIntent().getData();
    if (uri != null) {

        String token = uri.getQueryParameter("oauth_token");
        String verifier = uri.getQueryParameter("oauth_verifier");

        Log.v(TAG, "Token:" + token);
        Log.v(TAG, "Verifier:" + verifier);
    } else {

        CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                CONSUMER_KEY, CONSUMER_SECRET);

        // It uses this signature by default
        // consumer.setMessageSigner(new HmacSha1MessageSigner());

        CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
                REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTH_URL);

        String authUrl;
        try {
            authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
            Log.v(TAG, "Auth url:" + authUrl);

            startActivity(new Intent("android.intent.action.VIEW",
                    Uri.parse(authUrl)));

        } catch (OAuthMessageSignerException e) {
            Log.v(TAG, "Auth url:" + e.getMessage());
        } catch (OAuthNotAuthorizedException e) {
            Log.v(TAG, "Auth url:" + e.getMessage());
        } catch (OAuthExpectationFailedException e) {
            Log.v(TAG, "Auth url:" + e.getMessage());
        } catch (OAuthCommunicationException e) {
            Log.v(TAG, "Auth url:" + e.getMessage());
        }

    }

}

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onResume()
 */
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    Log.v(TAG, "onResume");
}
}

是否有其他Android SDK可用于在tumblr中共享照片。我究竟做错了什么..?

1 个答案:

答案 0 :(得分:0)

尝试使用此代替CALLBACK_URL,可能会解决您的问题。

public static final String OAUTH_CALLBACK_URL = "oauthflow-tumblr://callback";