[英]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.