开发者

Can't post to facebook wall with iOS SDK (authorization issue)

First i create facebook object with my appId:

facebook = [[Facebook alloc] initWithAppId:kAppId];

When i call

[_facebook authorize:_permissions delegate:self] 

my safari opens up and after i enter my FB username and password, safari closes and everything returns to my app (like it should). My permissions are:

_permissions =  [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil] retain];

The strange thing is that my delegate method - (void)fbDidLogin or -(void)fbDidNotLogin:(BOOL)cancelled is not called like in FB sample app that comes with SDK. In my .h file i implement protocols "FBRequestDelegate, FBDialogDelegate, FBSessionDelegate" and in .m file i have the necessary methods.

If i try to make a post after that with

[_facebook requestWithGraphPath:@"me/feed" 
        andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post" forKey:@"message"]
                  andHttpMethod:@"POST"
                    andDelegate:self];

i get error "req failed with error The operation couldn’t be completed. (facebookErrDomain error 10000.)". This must be something related to authorization, but since i get no message after authorize call, i don't know that开发者_如何学Python to do.

Any ideas?


NSMutableDictionary *params = [NSMutableDictionary  dictionaryWithObjectsAndKeys:
                      @"My new status message", @"message",
                      nil];
[_facebook requestWithGraphPath:@"/me/feed"
                  andParams:params
                  andHttpMethod:@"POST"
            andDelegate:self];

or

The error object returned has the details about what's happening. I suggest to implement that method to get more infos:

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);
};

For example for my problem gived me that info, and I've fixed it:

2011-05-27 11:19:57.313 Challengein[7704:207] The operation couldn’t be completed. (facebookErrDomain error 10000.)
2011-05-27 11:19:57.314 Challengein[7704:207] Err details: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x6878b90 {error=<CFBasicHash 0x6879be0 [0x141c400]>{type = mutable dict, count = 2,
entries =>
    2 : <CFString 0x6877f70 [0x141c400]>{contents = "type"} = <CFString 0x686f9a0 [0x141c400]>{contents = "OAuthException"}
    3 : <CFString 0x686d610 [0x141c400]>{contents = "message"} = <CFString 0x686f970 [0x141c400]>{contents = "(#100) picture URL is not properly formatted"}
}
}

please try this link http://www.capturetheconversation.com/technology/-facebook-oauth-2-0-and-the-graph-api-a-tutorial-part-2


same thing here. I followed Ben Biddington's blog to get the access token. Same error when trying to use it. Facebook's OAuth implementation doesn't follow the spec completely, i am fine with it as long as the doc is clear, which obviously is not the case here. Aslo, it would be nice if the userid and username are returned with the access token.

or

Just to clarify -- after you call

https://graph.facebook.com/oauth/authorize?

you should receive a CODE which, in conjunction with your CLIENT_ID and CLIENT_SECRET (assuming you have registered your application) can be exchanged for an access_token at

https://graph.facebook.com/oauth/access_token?

If this is indeed how you came by your ACCESS_TOKEN, you should then be able to request

https://graph.facebook.com/me/


For me to solve error 10000, just add

[facebook handleOpenURL:url];

in callback:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

info: This callback is called after ask permission like:

permissions =  [[NSArray arrayWithObjects:@"publish_stream",
                                          @"offline_access",
                                          nil] retain];
facebook = [[Facebook alloc] initWithAppId:@"yourappid"];
[facebook authorize:permissions delegate:self];

Then in this callback just call [facebook handleOpenURL:url] before trying to publish on wall. Calling [facebook handleOpenURL:url] call fbDidLogin callback !!

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    NSLog(@"URL: %@",url);  
    [facebook handleOpenURL:url];
    [facebook requestWithGraphPath:@"me/feed" 
                         andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post"
                                                                      forKey:@"message"]
                     andHttpMethod:@"POST"
                       andDelegate:self];
}

Twil


Let me guess, you extracted your FB code to another class instead of implementing it in your AppDelegate?

I believe the issue is that FB's page instructed us to do something like this in their demo code:

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

However, Facebook's demo code implemented the whole logic inside the AppDelegate. If you, like I, extracted the FB communication code to another class, the above code will not be properly executed (if you have the code in your AppDelegate the facebook variable isn't pointing to the right object. If you have the code in your extracted class, it will not get invoked) and your token info will not be included.

What I ended up doing is this:

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

where fbModel is an instance variable pointing to the code that does FB stuffs. And then in my fbMode implementation, I do something like this:

- (BOOL)handleOpenURL:(NSURL *)url
{
    return [facebook handleOpenURL:url];
}

Where facebook is an instacne variable in my FBModel class such that facebook = [[Facebook alloc] initWithAppId:AppID] was called at initialization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜