简体   繁体   English

Twitter Android-FirebaseUI身份验证:一旦我拥有Android应用上的访问令牌和访问密码,如何代表用户发布?

[英]Twitter Android-FirebaseUI auth: How to post on user's behalf once I have the access Token and the access secret on Android App??are those enough?

I logged in successfully and got the twitter access token and the twitter access secret using firebase-ui-auth [ https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md][1] : 我成功登录,并使用firebase-ui-auth [ https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md][1]获得了twitter访问令牌和twitter访问密码:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN && resultCode == RESULT_OK) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
       //twitter access token
        response.getIdpToken();
        //twitter access token secret
        response.getIdpSecret();
    }
}

I want to post on user's behalf(to their accounts, not to mine) using these two tokens that I will save on shared preferences. 我想使用将保存在共享首选项上的这两个令牌代表用户发布(到他们的帐户,而不是我的帐户)。

1) Are these two tokens enough to post to user's account? 1)这两个令牌足以发布到用户的帐户吗? 2) How do I do to post something using these two tokens?. 2)如何使用这两个令牌发布内容? I can't seem to find the proper docs for my particular case, the twitter api handling for android is really poor. 我似乎找不到适合我的特殊情况的文档,Android的twitter api处理真的很差。

I already solved it myself by using fabric and its TweetComposer class..... 我已经通过使用fabric及其TweetComposer类解决了它自己.....

first you need to initialize fabric on the bootstrap Class of your app 首先,您需要在应用程序的引导类上初始化结构

Fabric.with(this, new Twitter(authConfig));

then on the class you want to make the tweet you get the firebase instance to get the logged in user and then you set the twitter consumer key and secret that you got when you log in to firebase UI https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md , for future reference to get the two tokens needed to tweet on user's behalf you can do it like the link specifies: 然后在要发送鸣叫的类上,获取firebase实例以获取登录用户,然后设置登录到firebase UI https://github.com/firebase时获得的twitter使用者密钥和秘密/FirebaseUI-Android/blob/master/auth/README.md ,以供将来参考以获取代表用户进行鸣叫所需的两个令牌,您可以像链接中指定的那样进行操作:

To retrieve the ID token that the IDP returned, you can extract an IdpResponse from the result Intent. 要检索IDP返回的ID令牌,可以从结果Intent中提取IdpResponse。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        IdpResponse idpResponse = IdpResponse.fromResultIntent(data);
        startActivity(new Intent(this, WelcomeBackActivity.class)
                .putExtra("my_token", idpResponse.getIdpToken()));
    }
}

Twitter also returns an AuthToken Secret which can be accessed with idpResponse.getIdpSecret().

and now you have everything you need: 现在您拥有了所需的一切:

    mAuth = FirebaseAuth.getInstance();

            if (mAuth.getCurrentUser() != null) {
                // already signed in

                twitter_consumer_key= preferences.getString("TWITTER_CONSUMER_KEY","");
                twitter_consumer_secret= preferences.getString("TWITTER_CONSUMER_SECRET","");

                TwitterAuthConfig authConfig =  new TwitterAuthConfig(twitter_consumer_key, twitter_consumer_secret);
         //setting up fabric       
         Fabric.with(this, new TwitterCore(authConfig), new TweetComposer());


            }

and then let's say I want to tweet from a custom button onClick:

        ImageButton tweetButton= (ImageButton) findViewById(R.id.tweet_button);

tweetButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                TweetComposer.Builder builder = new TweetComposer.Builder(mContext)
                        .text("just setting up my Fabric.");
                builder.show();

            }
        });

the app will redirect you to the twitter app with the preseted message "just setting up my Fabric.". 该应用程序将通过预设消息“仅设置我的Fabric”将您重定向到Twitter应用程序。 You can add pictures and videos too! 您也可以添加图片和视频!

Hope that this helps someone in the future cause there is little info about fabric.... 希望这对以后的人有所帮助,因为关于面料的信息很少。

暂无
暂无

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

相关问题 使用Firebase的Twitter API:如何获取代表用户发布的twitter accessToken? 我已经成功登录 - Twitter API using Firebase: How do I get the twitter accessToken to post on user's behalf?? I already logged in successfully 重新验证用户。 使用 Android 的 FirebaseUI 身份验证 - Re-authenticate a user. with FirebaseUI auth for Android 在给定App ID和Secret的情况下,如何获取FB访问令牌? - How to get FB access token given App ID and Secret? 如何使您的android应用仅要求超级用户访问一次? - How to make your android app ask for superuser access only once? Twitter API,用于使用访问令牌和密码获取好友列表 - Twitter api for getting friends list using access token and secret 获取 Spotify API for Android 应用的访问令牌 - Get access token for Spotify API for Android app 如何使用参数Client_ID,Client_Secret,Auth_Url,Access_token_URL检索访问令牌? - How to retrieve access token, with parameters: Client_ID, Client_Secret, Auth_Url, Access_token_URL? 如何获得访问令牌和访问令牌秘密? - How do I get the Access-Token and Access-Token-Secret? 如何从Android中的演示者访问令牌? - How do I access a token from the presenter in Android? 在登录Facebook App并授权我的应用程序后,如何才能正确获取访问令牌和其他信息? [Android]产品 - How can I get Access Token and other info correctly after logging in Facebook App and authorizing my app? [Android]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM