在 Android 中使用 scribe 的 Twitter 代码问题

发布于 2025-01-07 12:26:19 字数 147 浏览 0 评论 0原文

我正在使用 scribe 在我的应用程序中实现 twitter。我能够登录并获取向用户显示的代码。这里的问题是,我必须强制用户手动输入代码,当他提交该代码时我将获得访问令牌。但我不想向用户显示此代码。相反,我可以使用此代码并使用验证程序来取回 accessToken。是否可以 ?

I am implementing twitter in my application using scribe.I am able to login and getting the code back which is showing to user. Here the problem is that, i have to force the user to manually type the code and when he submit that code i will get the access token. But i don't want to show this code to the user. Instead i can use this code and use the verifier to get the accessToken back. Is it possible ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-14 12:26:19
/*
    The below example assumes you already have the following variables:

    oAuth -> Scribe OAuthService Instance
    requestToken -> Request token received from your callback
    verifier -> Verifier received from your callback
*/

// GET ACCESS TOKEN

    Token accessToken = null;
    accessToken = oAuth.getAccessToken(requestToken, verifier);

// TEST ACCESS TOKEN BY GETTING A PROTECTED RESOURCE

    if (accessToken != null)
    {
        // CREATE, SIGN, AND SEND REQUEST

            OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.twitter.com/1/account/verify_credentials.json");
            oAuth.signRequest(accessToken, request);
            JSONObject response = new JSONObject (request.send().getBody());

        // EXTRACT NEEDED REQUEST RESPONSE VARIABLES (IN THIS CASE JUST THE SCREEN NAME AND TWITTER ID)
        // (NOTE: make sure to do some error checking to make sure accountName and networkAccountId are not empty)

            try
            {
                String accountName   = "@" + response.get("screen_name").toString();
                int networkAccountId = response.get("id").toString();
            }
            catch(Exception e)
            {
                // LOG ERROR MESSAGE

                    Log.e("Your_Tag","Get Access Token Error: " + e);
                    e.printStackTrace();
            }
    }
/*
    The below example assumes you already have the following variables:

    oAuth -> Scribe OAuthService Instance
    requestToken -> Request token received from your callback
    verifier -> Verifier received from your callback
*/

// GET ACCESS TOKEN

    Token accessToken = null;
    accessToken = oAuth.getAccessToken(requestToken, verifier);

// TEST ACCESS TOKEN BY GETTING A PROTECTED RESOURCE

    if (accessToken != null)
    {
        // CREATE, SIGN, AND SEND REQUEST

            OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.twitter.com/1/account/verify_credentials.json");
            oAuth.signRequest(accessToken, request);
            JSONObject response = new JSONObject (request.send().getBody());

        // EXTRACT NEEDED REQUEST RESPONSE VARIABLES (IN THIS CASE JUST THE SCREEN NAME AND TWITTER ID)
        // (NOTE: make sure to do some error checking to make sure accountName and networkAccountId are not empty)

            try
            {
                String accountName   = "@" + response.get("screen_name").toString();
                int networkAccountId = response.get("id").toString();
            }
            catch(Exception e)
            {
                // LOG ERROR MESSAGE

                    Log.e("Your_Tag","Get Access Token Error: " + e);
                    e.printStackTrace();
            }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文