0

Facebookに画像を投稿しようとしています。昨日は入手しましたが、今日はもう一度テストしましたが、機能しません:S。問題が見つかりません。私はいくつかのことを変更しましたが、Facebookが相互作用するメソッドはありません。誰かが私を助けてくれることを願っています。

ユーザーが要求したときにのみログインするため、viewControllerにすべてを取得しました。

私はそれをデバッグしました、そして私がそれを呼ぶので、「publishFacebook」だけが呼ばれます。Facebookにアクセスして権限を要求すると、戻っても何も起こりません。

URLスキームは正しいです。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb235694579858240</string>
        </array>
    </dict>
</array>
</plist>

ViewController.h

「FBConnect.h」をインポートします

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>

@property (nonatomic, retain) Facebook *facebook;
-(void)postWall;

ViewController.m

-(void) publishFacebook:(UIImage *)img { 
    
    //start the facebook action by clicking any button
    _publishedImage = img;
    _facebook = [[Facebook alloc] initWithAppId:@"235694579858240" andDelegate:self];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    
    if (![_facebook isSessionValid]) {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_photos",
                                @"user_likes", 
                                @"read_stream",
                                nil];
        _facebook.sessionDelegate = self;
        [_facebook authorize:permissions];
    }else{
        [self postWall];
    }
}
    
    
    - (void)fbDidLogin {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
        [defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];
        [defaults synchronize];
        [self postWall];
    }
    
    - (void)postWall{
        
        //NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
        NSData *imageData = UIImagePNGRepresentation(_publishedImage);
        //[NSData dataWithContentsOfFile:filePath]
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"Check out my awesome image!. I make it with Trolling for iOS", @"message", imageData, @"source", nil];
        [_facebook requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
        
        NSLog(@"Image posted");
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Image Posted" message:@"Your image was successfully posted of facebook" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alertView show];
    }
    
    -(void)fbDidNotLogin:(BOOL)cancelled{
        if (cancelled) {
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Could not Login" message:@"Facebook Cannot login please try again" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
            [alertView show];
        }
    }


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [_facebook handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [_facebook handleOpenURL:url]; 
} 

ありがとう

4

1 に答える 1

1

Facebookのチュートリアルに注意深く従う必要があり、すべてが機能するはずです:developers.facebook.com/docs/mobile/ios/build

必要な調整は、UIButtonIBAction呼び出しの結果としてログインプロセスを起動することだけです。残りはまったく同じフローです。これは非常にデリケートなプロセスであり、何かを見逃した場合にデバッグするのは非常に困難です。

于 2012-04-22T06:53:56.790 に答える