unable to post tweets to twitter using Outh
Iam Using Outh to add Twitter to my app and I got the mail from twitter team as.
Thank you for writing in and we will respect the confidentiality of your images. Your application now has the ability to use xAuth, and our docume开发者_如何学Pythonntation is available here: http://dev.twitter.com/pages/xauth .
Thanks, Twitter API Policy
Now Iam getting login to the twitter account with my app,but Iam unable to post the tweets.
Basically Iam using two different views one for login process and second one for posting the tweets.
My Questions is.
1.If I use only one view, tweets are posting.But as per my requirement I need to have post from another view.How I can achive?
Iam using this method to posting.
[_engine sendUpdate:str];
please help me here.
I think this will help you out:
Oauth authorization callback
AS like I answered for ur other post, U use the same _engine object in DetailViewController. You can Achieve this as follows, Declare a object for the same SA_Twitter....Engine some class. U just assign this _engine object to the detailviewController while you loading that controller
Do the following in the necessary place of SettingsViewController
//This engine object should be declared @ .h of settings
if ([SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:engine delegate:self]) {
[self presentModalViewController:[SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:engine delegate:self] animated:YES];
}
Declare a variable for SA_OAuthTwitterEngine in detailview
SA_OAuthTwitterEngine *_engine;
@property (nonatomic, retain) SA_OAuthTwitterEngine *_engine;
Finally while u moving from settigs to detailview,
DetailView *detailObj=[[DetailView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
detailObj._engine=self.engine;
[self presentModalViewController:detailObj animated:YES];
[detailObj release];
If you want to post what you have entered in text box, I may help you out here. 1. You must have included the twitter4j library in gradle file as follows:
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.1'
2. Include following code snippet in your code:
public String sTweet;
EditText et_TweetText;
public static String consumerkey = "xxxxxxxxxxxxxxxxx";
public static String consumersecret = "xxxxxxxxxxxxxxxxx";
public static String accesstoken="xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxx";
public static String accesstokensecret="xxxxxxxxxxxxxxxxx";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
et_TweetText = (EditText) view.findViewById(R.id.et_TweetText);
bt_tweetIt = (Button) view.findViewById(R.id.bt_tweetIt);
bt_tweetIt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
sTweet = et_TweetText.getText().toString();
Log.i(TAGTweet, "onClick- sTweet: " + sTweet);
if(CheckConnectivity()!=0){
Log.i(TAGTweet, "Internet Connection ON: ");
new UseTweeter().execute();
}
else {
Log.i(TAGTweet, "Internet Connection OFF: ");
ShowNoInternetConnectionAlert();
}
}
public class UseTweeter extends AsyncTask<String,String,String>{
@Override
protected String doInBackground(String... params) {
TweetThisMessage();
return null;
}
}
public void TweetThisMessage(){
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthAccessToken(accesstoken);
builder.setOAuthAccessTokenSecret(accesstokensecret);
builder.setOAuthConsumerKey(consumerkey);
builder.setOAuthConsumerSecret(consumersecret);
OAuthAuthorization auth = new OAuthAuthorization(builder.build());
Twitter twitter = new TwitterFactory().getInstance(auth);
try {
Log.i(TAGTweet, "sTweet in TweetThisMessage(): " + sTweet);
twitter.updateStatus(sTweet);
} catch (TwitterException e) {
e.printStackTrace();
return;
}
}
Hope it helps.
精彩评论