0

OAuth署名に問題があります。

私がretrieveRequestTokenを取得することを期待しているポイントで、私は次のエラーを受け取りました:

01-05 17:26:02.775: W/System.err(24358): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null

なぜこれを手に入れるのか分かりません。ここに何か提案はありますか?

私のコード:

connectionDec = new ConnectionDetector(getApplicationContext());

// Check if Internet present
if (!connectionDec.isConnectingToInternet())
{
// Internet Connection is not present
// alert.showAlertDialog(MainActivity.this,
// "Internet Connection Error",
// "Please connect to working Internet connection", false);
// stop executing code by return
return;
}

CommonsHttpOAuthConsumer consumer =
new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
CommonsHttpOAuthProvider provider =
new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL,
AUTHORIZE_URL);
provider.setOAuth10a(true);

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String token = sharedPreferences.getString("token", null);
String tokenSecret = sharedPreferences.getString("token_secret", null);

if (token == null || tokenSecret == null) 
{
Map requestHeaders = provider.getRequestHeaders();
requestHeaders.put("User-Agent", USER_AGENT);
requestHeaders.put("Accept-Encoding", "gzip");

try 
{
String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
}
catch (OAuthMessageSignerException e) 
{
e.printStackTrace();
}
catch (OAuthNotAuthorizedException e) 
{
e.printStackTrace();
}
catch (OAuthExpectationFailedException e) 
{
e.printStackTrace();
}
catch (OAuthCommunicationException e) 
{
e.printStackTrace();
}
}
else
{
}

ヒントと助け...ありがとう

PS:それはDiscogsであり、Twitterではありません

グリッツマッド

4

1 に答える 1

0

OK、私は自分で質問に答えました...次のようなasynctaskを実装しましたが、動作します:

public class StartUpActivity extends Activity implements OnClickListener
{

    private static String CONSUMER_KEY = "consumerkey";
    private static String CONSUMER_SECRET = "yourconsumersecret";
    private static String REQUEST_TOKEN_URL = "http://api.discogs.com/oauth/request_token";
    private static String AUTHORIZE_URL = "http://www.discogs.com/oauth/authorize";
    private static String ACCESS_TOKEN_URL = "http://api.discogs.com/oauth/access_token";
    private static String USER_AGENT = "youruseragent";
    private static String CALLBACK_URL = "http://www.callback.com";

    private ConnectionDetector connectionDec;
    private SharedPreferences sharedPreferences;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_up_layout);

        connectionDec = new ConnectionDetector(getApplicationContext());

        // Check if Internet present
        if (!connectionDec.isConnectingToInternet())
        {
            // Internet Connection is not present
            // alert.showAlertDialog(MainActivity.this,
            // "Internet Connection Error",
            // "Please connect to working Internet connection", false);
            // stop executing code by return
            return;
        }

    }

    class ProgressTask extends AsyncTask<Integer, Integer, Void>{

        @Override
        protected void onPreExecute() {
            // initialize the progress bar
            // set maximum progress to 100.
        }

        @Override
        protected void onCancelled() {
            // stop the progress
        }

        @Override
        protected Void doInBackground(Integer... params) {
            // get the initial starting value
            int start=params[0];
            // increment the progress
                try {
                    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
                    CommonsHttpOAuthProvider provider =
                            new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_URL);
                    provider.setOAuth10a(true);

                    // Check if token and tokensecret are already stored at app preferences
                    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    String token = sharedPreferences.getString("token", null);
                    String tokenSecret = sharedPreferences.getString("token_secret", null);

                    if (token == null || tokenSecret == null)
                    {
                        Map<String, String> requestHeaders = provider.getRequestHeaders();
                        requestHeaders.put("User-Agent", USER_AGENT);
                        requestHeaders.put("Accept-Encoding", "gzip");

                        try
                        {
                            String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
                        }
                        catch (OAuthMessageSignerException e)
                        {
                            e.printStackTrace();
                        }
                        catch (OAuthNotAuthorizedException e)
                        {
                            e.printStackTrace();
                        }
                        catch (OAuthExpectationFailedException e)
                        {
                            e.printStackTrace();
                        }
                        catch (OAuthCommunicationException e)
                        {
                            e.printStackTrace();
                        }
                    }
                    else
                    {

                    }

                    }

                 catch (Exception e) {
                }

            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            // increment progress bar by progress value
        }

        @Override
        protected void onPostExecute(Void result) {
            // async task finished
        }
    } 
}
于 2013-01-07T20:47:13.047 に答える