1

我正在尝试使用foursquare api登录foursquare。它显示登录页面,但当我尝试输入用户名或密码时崩溃。几天前它运行良好,但突然停止工作。

Server responded with:400, bad request
2012-08-24 14:44:25.227[1962:17903] contant data {"error":"invalid_grant"}
2012-08-24 14:44:25.228[1962:17903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: foursquare_access_token)'

请帮我 。为什么会出现这个错误?

4

2 回答 2

3

Foursquare 登录页面现在返回来自 Facebook 网站的请求。因此,您可以使用 FB 凭据登录 Foursquare。

其中一个响应破坏了Foursquare2逻辑 https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=10#cb=xxx&origin=https%3A%2F%2Ffoursquare.com%2Fxxx&domain=foursquare。 com&relation=parent&frame=xxx&错误=unknown_user

Foursquare2 在响应中寻找“error=”。如果找到它,它会执行委托回调。

要修复它,请替换您的 ' webView:shouldStartLoadWithRequest:navigationType:'

在 Foursquare2.m 中

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *url =[[request URL] absoluteString];

    if ([url rangeOfString:@"facebook.com"].location != NSNotFound)
        return YES; //ignore Facebook authentication

    if ([url rangeOfString:@"code="].length != 0) {

        NSHTTPCookie *cookie;
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (cookie in [storage cookies]) {
            if ([[cookie domain]isEqualToString:@"foursquare.com"]) {
                [storage deleteCookie:cookie];
            }
        }

        NSArray *arr = [url componentsSeparatedByString:@"="];
        [delegate performSelector:selector withObject:[arr objectAtIndex:1]];
        [self cancel];
    }else if ([url rangeOfString:@"error="].length != 0) {
        NSArray *arr = [url componentsSeparatedByString:@"="];
        [delegate performSelector:selector withObject:[arr objectAtIndex:1]];
        FourSquareLog(@"Foursquare: %@",[arr objectAtIndex:1]);
    } 
    return YES;
}

注意一个新的

if ([url rangeOfString:@"facebook.com"].location != NSNotFound)
    return YES; //ignore Facebook authentication
于 2012-08-24T20:56:07.073 回答
0

Get yout own key consumer key and secret for application on oauth

After having consumer key and secret for application update or replace in

 Constants.h file of your poject
于 2012-08-24T09:26:29.440 回答