2012-03-15 4 views
1

내 iOS 앱에 MGTwitterEngine 라이브러리를 사용하여 트윗을 게시합니다.iOS 용 MGTwitterEngine : 액세스 토큰을 얻는 방법? 오류 401

NSString *username = dataBase.twiLog; 
NSString *password = dataBase.twiPas;      

NSString *consumerKey = cons_key; 
NSString *consumerSecret = cons_secret; 

// Most API calls require a name and password to be set... 
    if (! username || ! password || !consumerKey || !consumerSecret) { 
     NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!"); 
     NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection."); 
}  
// Create a TwitterEngine and set our login details. 
MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self]; 
twitterEngine setClearsCookies:YES];       
[twitterEngine setUsesSecureConnection:NO]; 
[twitterEngine setConsumerKey:consumerKey secret:consumerSecret]; 

[twitterEngine setUsername:username password:password]; 
[twitterEngine sendUpdate: @"This message was sent via myApp for iOS"]; 

그러나 accessToken을 얻을 때까지는 트윗을 보낼 수 없습니다. 출력은 다음과 같습니다.

Request failed for connectionIdentifier = 5E7C9D2E-1467-45EF-B748-CCBF8F211F8D, error = The operation couldn’t be completed. (HTTP error 401.) ({ 
    body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <error>Could not authenticate you.</error>\n <request>/1/statuses/update.xml</request>\n</hash>\n"; 
    response = "<NSHTTPURLResponse: 0x6e26a10>"; 
}) 

어떻게 MGTwitterEngine을 사용하여 트윗을 보낼 수 있습니까? (다른 사용자가 자신도 트윗을 보낼 수 있어야하므로 dev.twitter.com에서 내 액세스 토큰을 수동으로받지 않아도 됨)

답변

0

비슷한 문제가 있으며 많은 시간 동안 검색 한 결과 해결책을 찾았습니다. 엔진이 isAuthorized인지 확인하여 사용자가 로그인 한 경우에만 내 로그 아웃 버튼이 표시됩니다. 그런 다음 사용자가 버튼을 두드린 후 이것이 실행되는 코드입니다.

- (void)logoutTwitter { 

if(![_engine isAuthorized]){ 
    UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self]; 

    if (controller){ 
     [self presentModalViewController: controller animated: YES]; 
    } 
} else { 
    [_engine clearAccessToken]; //This is a method called from SA_OAuthTwitterEngine.h 

은}

+0

는'_engine' 어떤 클래스의 목적은? 'MGTwitterEngine' 클래스는'isAuthorized'와'clearAccessToken' 메소드가 없습니다. –

+0

그것의 인스턴스는 SA_OAuthTwitterEngine입니다. 이 클래스는 OAuth를'MGTwitterEngine' (OAuth가 아닌 곳) –

관련 문제