簡體   English   中英

iOS:foursquare請求失敗

[英]iOS: foursquare request fails

我剛被分配到與Foursquare合作。 我有一個需要進行身份驗證並訪問Foursquare環境的應用程序。 我在使用以下代碼訪問簽入時遇到麻煩。 我已經成功進行了身份驗證,但事實是,當我提出簽入請求時,出現errorType invalid_auth代碼401。 我只是不知道這是怎么回事。

這是我的完整代碼; 我正在使用在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

你能幫我嗎? 任何幫助將不勝感激。

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

401(未經授權)已提供OAuth令牌,但無效。

您可能以某種方式損壞了您的oauth令牌?

我正在使用下面的代碼,它為我工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM