首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发布UIImage脸书问题

发布UIImage脸书问题
EN

Stack Overflow用户
提问于 2012-04-15 15:08:10
回答 1查看 183关注 0票数 0

我正试着把一张照片发到脸书上。昨天我得到了它,但今天我再次测试它,它不工作:S。我找不到问题。我修改了一些东西,但没有一个是Facebook与之交互的方法。我希望有人能帮助我。

我把所有东西都放在我的viewController中,因为它只在用户请求时登录。

我调试了它,只调用了"publishFacebook“,因为我调用了它。它转到Facebook并请求权限,然后你返回,什么也没有发生。

URL方案是正确的。

代码语言:javascript
复制
<?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“

代码语言:javascript
复制
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>

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

ViewController.m

代码语言:javascript
复制
-(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]; 
} 

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-22 14:53:57

你需要仔细地遵循Facebook的教程,一切都应该正常工作:developers.facebook.com/docs/mobile/ios/build

您需要做的唯一调整就是触发登录进程,这是UIButton IBAction调用的结果。其余的都是完全相同的流程。这是一个相当微妙的过程,如果您遗漏了一些东西,则很难进行调试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10160206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档