2015-06-06 76 views
3

我已將Google登錄集成到我的iOS應用中,並在登錄後檢索訪問令牌。我現在想要向Google授權API調用,但不確定如何執行此操作包括令牌。
有人可以分享一些我可以用來包含這個代碼嗎?
非常感謝,
盧克製作iOS授權的Google API調用

回答

2

你已經登錄並獲得令牌,創建服務實例,然後附加一個經過「授權」。谷歌的Objective-C的客戶端支持相當多的服務:https://code.google.com/p/google-api-objectivec-client/

下面是使用Google+的一個樣本:

的OBJ-C(與ARC啓用)

GTLServicePlus* plusService = [[GTLServicePlus alloc] init]; 
plusService.retryEnabled = YES; 

# set an authorizer with your tokens 
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication]; 

# submit authenticated queries, assuming your scopes & tokens are legit 
GTLQueryPlus *query = [GTLQueryPlus queryForPeopleListWithUserId:@"me" 
            collection:kGTLPlusCollectionVisible]; 


[plusService executeQuery:query 
     completionHandler:^(GTLServiceTicket *ticket, 
          GTLPlusPeopleFeed *peopleFeed, 
          NSError *error) { 
       // ... your callback ... 
     }]; 

斯威夫特

var plusService = GTLServicePlus() 
plusService.retryEnabled = true 

# set an authorizer with your tokens 
plusService.authorizer = GPPSignIn.sharedInstance().authentication 

if let plusQuery = GTLQueryPlus.queryForPeopleListWithUserId("me", 
       collection: kGTLPlusCollectionVisible) as? GTLPlusQuery { 
    // execute the query 
    plusService.executeQuery(plusQuery) { (ticket: GTLServiceTicket!, 
              peopleFeed: GTLPlusPeopleFeed!, 
              error: NSError!) -> Void in 
     // ... your callback ... 
    } 
} 

There is a sample使用Google Obj-C專門針對YouTube的API客戶端。查看229YouTubeSampleWindowController.m設置您的GTLServiceYouTube對象,行261查看與GTLQueryYouTube對象配合使用的示例。

還有一些不錯的CocoaDocsThis method可能是你之後的事情。

+0

您能否鏈接到哪個頁面?理想情況下,您可以爲YouTube提供一個equivilent嗎?我關注了這個鏈接,當我點擊這些服務時,它只是把我帶到他們開發人員的主頁上。感謝 – mylogon

+1

https://developers.google.com/+/mobile/ios/people,以及我自己的Swift示例代碼。這裏還有一個YouTube API示例:https://code.google.com/p/google-api-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample – sgammon

+0

添加了一些鏈接和代碼參考爲YouTube。希望那些幫助! – sgammon

0

這最終以BAHYouTubeOAuth解決,可用here
我跟這個創建者交談過,他說改變已經到來,並且關於更好的令牌處理。
如果它沒有正式更改,請查看我的修改here