1

I m using facebook and twitter share in my application ,here i want to share the default link and text without shows the share windows,i tried many ways but still i did not get the solution.

this is my code:

 NSString *str_face=[NSString stringWithFormat:@"Another insta from Dealnabit just claimed now, Got yours now"];
 SLComposeViewController *facebookPostVC =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook ];

[facebookPostVC addImage:[UIImage imageNamed:@"Default.png"]];

[facebookPostVC setInitialText:str_face];

[self presentViewController:facebookPostVC animated:YES completion:Nil];`

2 Answers 2

7

1.For Facebook using Accounts Framework and SLRequest of Social Framework without dialogue

-(void)Post
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookAccountType = [self.accountStore 
    accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Specify App ID and permissions
NSDictionary *options = @{
      ACFacebookAppIdKey: @"my app id",
      ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
      ACFacebookAudeinceKey: ACFacebookAudienceFriends
};

[accountStore requestAccessToAccountsWithType:facebookAccountType 
      options:options completion:^(BOOL granted, NSError *e) {
        if (granted) {
            NSArray *accounts = [self.accountStore 
                    accountsWithAccountType:facebookAccountType];
            facebookAccount = [accounts lastObject];
        }
        else
        {
            // Handle Failure
        }
}];

NSDictionary *parameters = @{@"message": @"test post"};

NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];

SLRequest *feedRequest = [SLRequest 
        requestForServiceType:SLServiceTypeFacebook
        requestMethod:SLRequestMethodPOST 
        URL:feedURL 
        parameters:parameters];

    feedRequest.account = self.facebookAccount;

    [feedRequest performRequestWithHandler:^(NSData *responseData, 
           NSHTTPURLResponse *urlResponse, NSError *error)
    {
        // Handle response
    }];
}
  1. Twitter Post iOS6 without dialogue

      -(void)PostToTwitter
      {
    
     ACAccountStore *account = [[ACAccountStore alloc] init];
     ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:   
    ACAccountTypeIdentifierTwitter];
    
    [account requestAccessToAccountsWithType:accountType options:nil 
           completion:^(BOOL granted, NSError *error)
      {
     if (granted == YES)
     {
          NSArray *arrayOfAccounts = [account 
                 accountsWithAccountType:accountType];
    
          if ([arrayOfAccounts count] > 0)
          {
            ACAccount *twitterAccount = [arrayOfAccounts lastObject];
    
            NSDictionary *message = @{@"status": @”Test Twitter post from iOS 6”};
    
            NSURL *requestURL = [NSURL 
             URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
    
            SLRequest *postRequest = [SLRequest 
                requestForServiceType:SLServiceTypeTwitter
                       requestMethod:SLRequestMethodPOST
                       URL:requestURL parameters:message];
          }
     }];
      }
       }
    
3
1

I think the Twitter example post is missing to perform the request:

 // Post the request
 [postRequest setAccount:twitterAccount];

 // Block handler to manage the response
 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
      {
       NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
      }];

And I would use the latest version of API and https:

NSURL *requestURL = [NSURLURLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.