我在Social framwork中通过SLComposeViewController开发了社交(Facebook,Twitter)共享。有可能在SLComposeViewControllerCompletionHandler中获取发布的facebook,twitter共享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 :(得分: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]);
}
}];