gpt4 book ai didi

ios - 如何使用 SLRequest 通过 iOS 更改为通过

转载 作者:行者123 更新时间:2023-11-29 13:12:59 24 4
gpt4 key购买 nike

我浏览了很多链接和教程,但对我不起作用。谁能解释一下如何使用 SLRequest 通过 iOS 更改为通过 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
}];
}

最佳答案

首先使用 Facebook developer account setting 设置你的 facebook 设置

然后重置您的模拟器或从设备中删除应用。

添加并导入这个框架

#import <Accounts/Accounts.h>
#import <Social/Social.h>
#import <AdSupport/AdSupport.h>
#import <FacebookSDK/FacebookSDK.h>

使用此代码进行进一步处理

在你的class.h文件中

@property (nonatomic, strong)ACAccountStore *accountStore;

在你的class.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------------------

}

希望对您有所帮助。谢谢

关于ios - 如何使用 SLRequest 通过 iOS 更改为通过 <AppName>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16728969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com