简体   繁体   English

在Android上使用Scribe OAuth Java库时出错

[英]Error while using Scribe OAuth Java library on android

I'm using Scribe library on android to get Flickr OAuth token. 我在Android上使用Scribe库获取Flickr OAuth令牌。

I used the same example provided at 我使用了提供的相同示例

https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/FlickrExample.java https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/FlickrExample.java

with System.out.println replaced with Log.d. 将System.out.println替换为Log.d。

 private static final String PROTECTED_RESOURCE_URL = "https://api.flickr.com/services/rest/";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Replace these with your own api key and secret
        String apiKey = "xxxx989907fxxxxxxxxxxxxxxxxxxxx";
        String apiSecret = "fbxxxxx7dxxxxx8";
        OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
        Scanner in = new Scanner(System.in);

        Log.d("","=== Flickr's OAuth Workflow ===");
        System.out.println();

        // Obtain the Request Token
        Log.d("", "Fetching the Request Token...");
        Token requestToken = service.getRequestToken();
        Log.d("", "Got the Request Token!");
        System.out.println();

        Log.d("", "Now go and authorize Scribe here:");
        String authorizationUrl = service.getAuthorizationUrl(requestToken);
        Log.d("", authorizationUrl + "&perms=read");
        Log.d("", "And paste the verifier here");
        Log.d("", ">>");
        Verifier verifier = new Verifier(in.nextLine());
        System.out.println();

        // Trade the Request Token and Verfier for the Access Token
        Log.d("", "Trading the Request Token for an Access Token...");
        Token accessToken = service.getAccessToken(requestToken, verifier);
        Log.d("", "Got the Access Token!");
        Log.d("", "(if your curious it looks like this: " + accessToken + " )");
        Log.d("", "(you can get the username, full name, and nsid by parsing the rawResponse: " + accessToken.getRawResponse() + ")");
        System.out.println();

        // Now let's go and ask for a protected resource!
        Log.d("", "Now we're going to access a protected resource...");
        OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
        request.addQuerystringParameter("method", "flickr.test.login");
        service.signRequest(accessToken, request);
        Response response = request.send();
        Log.d("", "Got it! Lets see what we found...");
        System.out.println();
        Log.d("", response.getBody());

        System.out.println();
        Log.d("", "Thats it man! Go and build something awesome with Scribe! :)");
    }

I get this error - 我收到此错误-

There was a problem while creating a connection to the remote service. 创建与远程服务的连接时出现问题。

what is the problem here ? 这里有什么问题 ?

For your Information: 供你参考:

The Network operations should not be used in the Main UI Thread. 网络操作不应在主UI线程中使用。 Do these operation as Background operation. 将这些操作作为后台操作进行。

See AsyncTask in Android for more details. 有关更多详细信息,请参见Android中的AsyncTask It solve the connection network problem. 解决了连接网络的问题。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM