2014-05-22 80 views
0

我已經開發了通過社交框架中的SLComposeViewController進行社交(Facebook,Twitter)共享。可以在SLComposeViewControllerCompletionHandler中獲得facebook,twitter共享的帖子ID嗎?如何在SLComposeViewController ios中獲取twitter,facebook共享ID?

如果有可能建議我一些例子。

示例代碼

 SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){ 

     NSLog(@"here how to get the post shared id?"); 
    } ; 

    [tweetSheet setInitialText:@"Sharing from my own app! :)"]; 
    [self presentViewController:tweetSheet animated:YES completion:nil]; 
+0

SLComposeViewController * tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){ NSLog(@「」); }; 在完成處理程序方法中,它只會返回結果代碼。但我需要facebook,twitter post共享ID。它可能通過社交框架在iOS? – harigharan

+0

請將您的代碼添加到您的問題。 – lucianomarisi

回答

0

這是不可能通過SLComposeViewControllerCompletionHandler得到了Facebook,Twitter發佈共享ID。

取而代之,我使用SLRequest在twitter和facebook上共享帖子並獲取帖子的共享ID。

實施例代碼

NSLog(@"share on Facebook"); 
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"]; 

SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook 
               requestMethod:SLRequestMethodPOST 
                  URL:url 
                parameters:postparameter]; 

facebookRequest.account = facebookAccount;//Facebook Account Object 

[facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
    NSDictionary *postResponseData = nil; 
    NSString *fbShareId = nil; 
    if (responseData) { 

     NSInteger statusCode = urlResponse.statusCode; 
     if (statusCode >= 200 && statusCode < 300) { 
      postResponseData = [NSJSONSerialization JSONObjectWithData:responseData 
                   options:NSJSONReadingMutableContainers 
                   error:NULL]; 
      fbShareId = postResponseData[@"id"]; 
      NSLog(@"[SUCCESS!] Created post in facebook with ID: %@", fbShareId); 

     } 
     else { 
      NSLog(@"[ERROR] Server responded: status code %d %@", statusCode, 

        [NSHTTPURLResponse localizedStringForStatusCode:statusCode]); 

     } 
    } 
    else { 
     NSLog(@"[ERROR] An error occurred while posting: %@", [error localizedDescription]); 

    } 

}]; 
相關問題