0

我正在我的Facebook应用程序上添加共享功能。有关我的 iOS 应用程序的任何信息。如何让每个人都知道这句话是通过我的 iOS 应用程序共享的?请帮我....

4

1 回答 1

1

我可能有点晚了。希望这可以帮助。

您必须使用 Accounts 框架和 Social 框架来与您的应用程序名称共享。首先确保您在 Facebook 上正确设置了您的应用程序。然后,您可以使用 Facebook 应用 ID 通过您的应用分享您的帖子。

这是一个示例代码,向您展示如何将 Accounts 框架与 Social Framework 一起使用:

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

    // At first, we only ask for the basic read permission
    NSArray * permissions = @[@"email"];

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"275485699289493", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];

    NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
    //it will always be the last object with single sign on
    self.facebookAccount = [accounts lastObject];

    [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
        if (granted && error == nil) {
            /**
             * The user granted us the basic read permission.
             * Now we can ask for more permissions
             **/
            NSArray *readPermissions = @[ @"publish_actions"];
            [dict setObject:readPermissions forKey: ACFacebookPermissionsKey];

            [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
                if(granted && error == nil) {


                    NSDictionary *parameters = @{@"message": @"This Should Work Perfectly !! "};

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

                } else {
                    NSLog(@"error is: %@",[error description]);
                }
            }];
        } else {
            NSLog(@"error is: %@",[error description]);
        }
    }];
}
于 2014-07-04T12:40:16.120 回答