I'm having trouble in posting a reply to a specific status ID
Here's my authentication code
twitterWithReply = [STTwitterAPI twitterAPIOSWithFirstAccount];
[twitterWithReply verifyCredentialsWithSuccessBlock:^(NSString *username) {
NSLog(#"Login Successful");
self.replyTextField.enabled = YES;
}
errorBlock:^(NSError *error){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}];
And here's my code for posting the reply
NSLog(#"the text content%#",self.replyTextField.text);
[self.replyTextField resignFirstResponder];
if (self.replyTextField.text.length>0 && self.replyTextField.text.length <=140) {
// Post reply
[twitterWithReply postStatusUpdate:self.replyTextField.text inReplyToStatusID:self.tweeetID latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil successBlock:^(NSDictionary *status) {
[self showSuccessDialog];
} errorBlock:^(NSError *error) {
NSLog(#"%#",[error localizedDescription]);
}];
}
Currently what it does is to post to my own timeline not in reply to a specific tweet. I'm under the impression that my authentication code is wrong. So how do I authenticate then?
I just checked this scenario with the development version of STTwitter and it works as expected.
If this code doesn't work for you, then please fill an issue with as much details as possible.
self.twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[_twitter postStatusUpdate:#"test1" inReplyToStatusID:nil latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil successBlock:^(NSDictionary *status) {
NSLog(#"-- status1: %#", status);
[_twitter postStatusUpdate:#"test2" inReplyToStatusID:[status valueForKey:#"id_str"] latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil successBlock:^(NSDictionary *status) {
NSLog(#"-- status2: %#", status);
} errorBlock:^(NSError *error) {
NSLog(#"-- error2: %#", error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error1: %#", error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error0: %#", error);
}];
Related
i am used STTweeter for posting Tweets but it showing EXC_BAD_ACESS Error
and showing error STTwitterTwitter ErrorDomain code 220
My code
- (void)setOAuthToken:(NSString *)token oauthVerifier:(NSString *)verifier {
// in case the user has just authenticated through WebViewVC
[self dismissViewControllerAnimated:YES
completion:^{//
}];
[_twitter postAccessTokenRequestWithPIN:verifier
successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret,
NSString *userID, NSString *screenName) {
NSLog(#"-- screenName: %#", screenName);
self.twitter = [STTwitterAPI
twitterAPIAppOnlyWithConsumerKey:_consumerKeyTextField.text
consumerSecret:_consumerSecretTextField.text];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[_twitter postStatusUpdate:#"tweet text"
inReplyToStatusID:nil
latitude:nil
longitude:nil
placeID:nil
displayCoordinates:nil
trimUser:nil
successBlock:nil
errorBlock:nil];
NSLog(#"Sucess");
} errorBlock:^(NSError *error) {
NSLog(#"_____ERROR____%#", error);
}];
_loginStatusLabel.text = screenName;
}
errorBlock:^(NSError *error) {
_loginStatusLabel.text = [error localizedDescription];
NSLog(#"-- %#", [error localizedDescription]);
}];
}
I am having a very hard time here. There is one part in my application that STTwitter is successful and there is another part (using the same code) that does not return anything.
The part that does NOT work: `
-(IBAction)followTwitter:(id)sender {
if ([[NSUserDefaults standardUserDefaults] objectForKey:#"twitter_on_file" ] == nil) {
UIAlertView *allert = [[UIAlertView alloc] initWithTitle:#"Uh oh!" message:#"You have not linked your twitter account quite yet! Head to My Account settins to do so." delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[allert show];
} else {
ACAccountStore *store1 = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [store1 accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
if ([twitterAccountType accessGranted]) {
[store1 requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
arrayOfUsernames = [[NSMutableArray alloc] init];
iosAccounts = [store1 accountsWithAccountType:twitterAccountType];
for (ACAccount *accou in iosAccounts) {
[arrayOfUsernames addObject:accou.username];
}
NSString *usernameOnFile = [[NSUserDefaults standardUserDefaults] objectForKey:#"twitter_on_file" ];
int tracker = 0;
for (NSString *username in arrayOfUsernames) {
if ([username isEqualToString:usernameOnFile]) {
NSLog(#"Using twitter account: %#", username);
STTwitterAPI *twitterAPI = [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[tracker]];
[twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username) {
NSLog(#"Successfully authenticated the user");
} errorBlock:^(NSError *error) {
NSLog(#"Erorr: %#", error);
}];
NSLog(#"Twitter API: %#", twitterAPI);
[twitterAPI postFriendshipsCreateForScreenName:#"kickscaterer" orUserID:nil successBlock:^(NSDictionary *befriendedUser) {
NSLog(#"Befriend %#", befriendedUser);
} errorBlock:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
} else {
tracker++;
}
}
}];
}
}
}
`
The part that DOES work:
STTwitterAPI *twitter= [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[indexForAlert.row]];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
// ...
NSLog(#"Username: %#", username);
// [self.tableView reloadData];
[[NSUserDefaults standardUserDefaults] setObject:twitter.userName forKey:#"twitter_on_file"];
} errorBlock:^(NSError *error) {
NSLog(#"Error: %#", error);
// ...
}];
[twitter postFriendshipsCreateForScreenName:#"didi4" orUserID:nil successBlock:^(NSDictionary *befriendedUser) {
NSLog(#"Befriend %#", befriendedUser);
} errorBlock:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
Thanks!
The postFriendshipsCreateForScreenName: method should be called inside the success block, at the same level than the log "Successfully authenticated the user".
I have received my API key for the twitter API.
Currently my request looks like this
NSString *twitterURL = [NSString stringWithFormat:#"https://api.twitter.com/1.1/search/tweets.json?q=xyz&count=20"];
Now how do I build my request url with my API key?
You can use the STTwitter library.
STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:#""
consumerSecret:#""
oauthToken:#""
oauthTokenSecret:#""];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[_twitter getSearchTweetsWithQuery:#"xyz"
successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {
NSLog(#"-- statuses: %#", statuses);
} errorBlock:^(NSError *error) {
NSLog(#"-- error: %#", error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error: %#", error);
}];
I am new to ios app development. I want to learn facebook integration in ios and fetching friend list.
I follow the git hub code https://github.com/facebook/facebook-ios-sdk/tree/master/samples/FriendPickerSample
and follow all the step for that. my code is :
- (IBAction)friendPicker:(id)sender {
if (!FBSession.activeSession.isOpen)
{
// permission : [NSArray arrayWithObjects:#"email", #"read_friendlists", #"user_photos", #"user_events", nil]
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
else if (session.isOpen)
{
// [FBSession setActiveSession:session];
[self friendPicker:sender];
}
}];
return;
}
if(FBSession.activeSession.isOpen)
{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
if(error)
{
NSLog(#"error : %#",error);
}
else
{
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"total array : %#",result);
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
}
}
}];
}
if(self.friendPickerController == nil)
{
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = #"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentViewController:self.friendPickerController animated:YES completion:nil];
}
-(void)fillTextAndDismiss:(NSString * )text
{
[self.selectedFrdView setText:text];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)facebookViewControllerDoneWasPressed:(id)sender
{
NSMutableString *text = [[NSMutableString alloc] init];
for(id<FBGraphUser> user in self.friendPickerController.selection)
{
if([text length])
{
[text appendString:#", "];
}
[text appendString:user.name];
}
[self fillTextAndDismiss:text.length >0 ? text : #"<none>"];
}
-(void)facebookViewControllerCancelWasPressed:(id)sender
{
[self fillTextAndDismiss:#"<cancelled>"];
}
I also create facebookAppId and plist file is also updated by this key.
then also I am getting this error :
2014-05-12 14:21:27.043 fbFrndTest[2753:90b] error : Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb166450 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Unknown fields: username.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb521fd0, state: FBSessionStateOpen, loginHandler: 0x0, appID: 1481684055397512, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb523240>, expirationDate: 2014-07-11 05:48:12 +0000, refreshDate: 2014-05-12 07:26:43 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
)>}
The GitHUB code worked successfully, but my code gives an error.
I believe you're supposed to uncomment
//[FBSession setActiveSession:session];
Also double check that you're logged into Facebook on your simulator under Settings
Fetching Facebook Friends with Using FBRequest
Xcode 8.2.1 and Objective
FBRequest *friendRequest = [FBRequest requestForGraphPath:#"me/friends?fields=name,picture,birthday,email,location"];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if(error == nil) {
NSArray *data = [result objectForKey:#"data"];
for (FBGraphObject<FBGraphUser> *friend in data)
{
// [delegate.friendsListArray addObject:friend];
NSLog(#"%#:%#:%#:", [friend name],[friend birthday],[friend id]);
NSString *email=[friend objectForKey:#"email"];
NSLog(#"Email:%#",email);
}
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Facebook" message:#"Success in fetching Facebook Friends." delegate:self cancelButtonTitle:#"OK"otherButtonTitles:nil, nil];
[alert show];
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Facebook" message:#"Problem in fetching Facebook Friends. Try Later!" delegate:self cancelButtonTitle:#"OK"otherButtonTitles:nil, nil];
[alert show];
}
}];
I'm currently trying to implement the Facebook-Login-Flow with iOS Facebook SDK 3.1.
But there is a little Problem with it. Every time the user logs in with facebook the webview will open up and says
"You have already authorized YOUR_APP.."
The code I wrote based on the following example: click here
Now my question is, how can I avoid this behaviour and what I am doing wrong?
Please see this code ,it may help
postParams=
[#{
#"link" :link,
#"picture" :picture link , //[NSString stringWithFormat:#"%#%#",KBaseImageUrl,#"/assets/img/logo-small.jpg"],
#"name" : #“name”,
#"caption" : caption title,
#"description" :discription
} mutableCopy];
title=[[arrayEventInfo valueForKey:#"info"] valueForKey:#"eventname"];
if ([[FBSession activeSession]isOpen])
{
if ([[[FBSession activeSession]permissions]indexOfObject:#"publish_actions"] == NSNotFound)
{
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:#"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
}
else
{
alertText = #"Posted successfully on your wall.";//[NSString stringWithFormat:
//#"Posted action, id: %#",
// result[#"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}];
}else
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
}
else
{
alertText = #"Posted successfully on your wall.";//[NSString stringWithFormat:
//#"Posted action, id: %#",
// result[#"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
if (!error)
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
}
else
{
alertText = #"Posted successfully on your wall.";//[NSString stringWithFormat:
//#"Posted action, id: %#",
// result[#"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}else{
NSLog(#"%#",[error description]);
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}
}];
}
If you are testing the code in dev then the first time you log in it will store that session on Facebook.
So, you try to test it again but it is already authorized.
If you want to test the login process again then go to Facebook and de-authorize your app (it will be in your list of apps).
Then you can log in again on the device.