gpt4 book ai didi

ios - 在 iOS 6 中使用 SLRequest 发布到 Facebook

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:49:30 27 4
gpt4 key购买 nike

尝试让我的应用程序使用 SLRequest 向 Facebook 发布简单的帖子,但遇到了问题。权限被授予很好,它只是不会发布。

-(void)requestPermissions
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
__block ACAccount *facebookAccount = nil;

ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"MYAPPID",
ACFacebookPermissionsKey: @[@"email", @"user_about_me", @"user_likes"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};

[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options completion:^(BOOL granted, NSError *e)
{
if (granted) {

NSDictionary *options2 = @{
ACFacebookAppIdKey: @"MYAPPID",
ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

facebookAccount = [accounts lastObject]; }
else {
NSLog(@"Access denied 2");
NSLog(@"%@", [error description]);
}
}];
} else {
NSLog(@"Error: %@", [e description]);
NSLog(@"Access denied");
}
}];

NSDictionary *parameters = @{@"message": @"This is a test"};

NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];

SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
NSLog(@"AnythingHere?");
feedRequest.account = facebookAccount;

[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
// Handle response
NSLog(@"%@%@%@", error, responseData, urlResponse);
}];
}

日志中的错误在最后一部分返回 null。对此有什么想法吗?

更新:所以问题是 HTTP 响应返回为 400。

最佳答案

您应该犯了复制/粘贴错误。

选项已被实例化两次以及您互锁的两个 requestAccessToAccountsWithType 方法。

这看起来很常见且不太可能:

NSDictionary *options = @{...};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *e) {
if (granted) {
NSDictionary *options2 = @{...};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) {
if (granted)
...
else
...
}];
} else {
...
}
}];

你应该从the beginning重新开始.

关于ios - 在 iOS 6 中使用 SLRequest 发布到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14219706/

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