我经历了许多链接和教程,但没有为我工作。 任何人都可以解释我如何通过iOS使用SLRequest进行更改通过MyAppName?一步一步或给我一些链接,逐步提供这个解决方案。
编辑:我试过了。以下是我的代码可能会有所帮助。 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"012345678912345",
ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options completion:^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [accountStore
accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];
}
else
{
// Handle Failure
}
}];
NSDictionary *parameters = @{@"message": @"My first iOS 6 Facebook posting "};
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
}];
}
答案 0 :(得分:1)
首先使用Facebook developer account setting
设置你的facebook设置然后从设备重置您的simular或删除应用。
添加并导入此框架
#import <Accounts/Accounts.h>
#import <Social/Social.h>
#import <AdSupport/AdSupport.h>
#import <FacebookSDK/FacebookSDK.h>
使用此代码进行进一步处理
@property (nonatomic, strong)ACAccountStore *accountStore;
yourclass.m文件中的
@synthesize accountStore;
- (IBAction)facebookButtonTouch:(id)sender {
if (self.accountStore == nil)
self.accountStore = [[ACAccountStore alloc] init];
__block ACAccount *facebookAccount = nil;
ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = @[@"publish_stream", @"publish_actions",@"email"];
NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"your app id", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType
options:options completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *readPermissions = @[@"read_stream", @"read_friendlists"];
[options setObject:readPermissions forKey: ACFacebookPermissionsKey];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if(granted && error == nil) {
/**
* We now should have some read permission
* Now we may ask for write permissions or
* do something else.
**/
} else {
NSLog(@"error is: %@",[error description]);
}
}];
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];
}
else {
NSLog(@"error.localizedDescription======= %@", error.localizedDescription);
}
}];
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];
//-------------- start code for posting message on wall via SLRequest------------------
NSDictionary *parameters = @{@"message": @"Hi Friends i m ....."};
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(@"responseData %@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
//-------------- end code for posting message on wall via SLRequest------------------
}
我希望它会对你有所帮助。感谢