我尝试在我的应用中发布一条facebook帖子。我通过应用程序发布更新的任何时候都会出现弹出错误,上面写着
"there was a problem with posting your status. we've logged the error and will look into it"
我直接在我的iphone上测试过它。
下面是我的FBManager单例代码:
FBManager.h:
#import <Foundation/Foundation.h>
#import <FacebookSDK/FacebookSDK.h>
@interface FBManager : NSObject{
}
+(instancetype)sharedFBManager;
- (void)postUpdateWithShareDialog;
@end
FBManager.m
#import "FBManager.h"
@implementation FBManager
+(instancetype)sharedFBManager
{
static FBManager *fbManager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
fbManager = [[self alloc]init];
});
return fbManager;
}
-(instancetype)init
{
if (self = [super init]) {
NSLog(@"Facebook manager created");
}
return self;
}
- (void)postUpdateWithShareDialog {
// Check if the Facebook app is installed and we can present the share dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://developers.facebook.com/docs/ios/share/"];
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
// Present share dialog
[FBDialogs presentShareDialogWithLink:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
// Success
NSLog(@"result %@", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
// FALLBACK: publish just a link using the Feed dialog
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"]) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];
}
}
// A function for parsing URL parameters returned by the Feed Dialog.
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
@end
我通过调用
测试了它- (void)postUpdateWithShareDialog;
满足特定条件时的方法。我该如何解决这个问题?