2013-03-21 70 views
1

我在我的應用程序中使用Facebook和Twitter共享,在這裏我想分享默認鏈接和文本而不顯示共享窗口,我嘗試了很多方法,但仍然沒有得到解決方案。如何在ios 6的facebook和twitter上自動共享?

這是我的代碼:

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];` 

回答

7

1.對於Facebook的使用帳戶框架和社會框架的SLRequest沒有對白

-(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發佈iOS6的無對話

    -(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]; 
         } 
    }]; 
        } 
        } 
    
+0

@maddysan:是它的工作? – BhushanVU 2013-03-22 05:25:18

+0

其不工作的應用程序崩潰,請給出任何示例應用程序鏈接。 – maddysan 2013-03-22 09:22:43

+0

奇怪的原因,它在我的工作結束,反正看看這個http://blogs.captechconsulting.com/sites/default/files/TempFBapp.zip – BhushanVU 2013-03-22 09:24:02

1

我認爲Twitter的例子後缺少執行請求:

// 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]); 
     }]; 

而且我會使用最新版本的API和https的:

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