简体   繁体   English

iOS:foursquare请求失败

[英]iOS: foursquare request fails

I am assigned to work with foursquare just recently. 我刚被分配到与Foursquare合作。 I have an app that needs to be authenticated and access the foursquare environment. 我有一个需要进行身份验证并访问Foursquare环境的应用程序。 I am having trouble with the following code to access checkins. 我在使用以下代码访问签入时遇到麻烦。 I had already successfully made the authentication but the thing is that when I made a check in request, an errorType invalid_auth code 401 appears. 我已经成功进行了身份验证,但事实是,当我提出签入请求时,出现errorType invalid_auth代码401。 I just don't know what's wrong with this. 我只是不知道这是怎么回事。

Here is my full code; 这是我的完整代码; I am using fsq wrapper I found in github: 我正在使用在github中找到的fsq包装器:

#import "FSQViewController.h"

#define kClientID      @"XXXXXXXXXXXXXXXXXXXXXXX"
#define kCallbackURL   @"invitation://foursquare"

@interface FSQViewController()
@property(nonatomic,readwrite,strong) BZFoursquare *foursquare;
@property(nonatomic,strong) BZFoursquareRequest *request;
@property(nonatomic,copy) NSDictionary *meta;
@property(nonatomic,copy) NSArray *notifications;
@property(nonatomic,copy) NSDictionary *response;
@end


@implementation FSQViewController

@synthesize foursquare = foursquare_;
@synthesize request = request_;
@synthesize meta = meta_;
@synthesize notifications = notifications_;
@synthesize response = response_;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (id) initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if(self){
        self.foursquare = [[BZFoursquare alloc]initWithClientID:kClientID callbackURL:kCallbackURL];
        foursquare_.version = @"20120206";
        foursquare_.locale = [[NSLocale currentLocale]objectForKey:NSLocaleLanguageCode];
        foursquare_.sessionDelegate = (id<BZFoursquareSessionDelegate>) self;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}



#pragma mark -
#pragma mark BZFoursquareRequestDelegate

- (void)requestDidFinishLoading:(BZFoursquareRequest *)request {
    NSLog(@"test");
    self.meta = request.meta;
    self.notifications = request.notifications;
    self.response = request.response;
    self.request = nil;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)request:(BZFoursquareRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"HERE > %s: %@", __PRETTY_FUNCTION__, error);
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:[[error userInfo] objectForKey:@"errorDetail"] delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil];
    [alertView show];
    self.meta = request.meta;
    self.notifications = request.notifications;
    self.response = request.response;
    self.request = nil;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

#pragma mark -
#pragma mark BZFoursquareSessionDelegate

- (void)foursquareDidAuthorize:(BZFoursquare *)foursquare {
    NSLog(@"authorized!");
}

- (void)foursquareDidNotAuthorize:(BZFoursquare *)foursquare error:(NSDictionary *)errorInfo {
    NSLog(@"not authorized! %s: %@", __PRETTY_FUNCTION__, errorInfo);
}

- (IBAction)click:(id)sender {

    if (![foursquare_ isSessionValid]){ 
        NSLog(@"here");
        [foursquare_ startAuthorization];
    } else {
        [foursquare_ invalidateSession];
    }
}

- (IBAction)checkin:(id)sender {
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"4d341a00306160fcf0fc6a88", @"venueId", @"public", @"broadcast", kClientID, @"oauth_token", nil];
    self.request = [foursquare_ requestWithPath:@"checkins/add" HTTPMethod:@"POST" parameters:parameters delegate:self];
    [request_ start];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

@end

can you help me guys? 你能帮我吗? any help will highly be appreciated. 任何帮助将不胜感激。

https://developer.foursquare.com/overview/responses https://developer.foursquare.com/overview/responses

401 (Unauthorized) The OAuth token was provided but was invalid. 401(未经授权)已提供OAuth令牌,但无效。

Might you have somehow corrupted your oauth token? 您可能以某种方式损坏了您的oauth令牌?

我正在使用下面的代码,它为我工作:

NSDictionary *parameters = @{@"venueId": @"4a0c6465f964a5202a751fe3", @"broadcast": @"public",@"oauth_token":kClientID};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM