2016-06-15 5 views
0

私のアプリでGoogle + signInを実装しました.Google OAuth APIを使用してユーザーの誕生日を取得したいと考えています.Google開発者のplayground.butを使用して既にユーザーの誕生日を迎えましたが、iOSでユーザーの誕生日を取得する方法(迅速な)プログラムで?iosでoauth 2 apiを使用してgoogle plusからユーザーの誕生日を取得するにはどうすればよいですか?

ご協力いただければ幸いです。

答えて

1

あなたはこの方法でのOAuth APIを使用してプラスGoogleからの誕生日を取得することができます。すべての

まずあなたが誕生日に取得する範囲を設定する必要が

signIn.scopes = ["me", "profile"] 

let url : String = "https://www.googleapis.com/plus/v1/people/me" 
    let request : NSMutableURLRequest = NSMutableURLRequest() 
    request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") 
    request.URL = NSURL(string: url) 
    request.HTTPMethod = "GET" 
    print(request) 
    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue()) { (response : NSURLResponse?, data:NSData?, error:NSError?) -> Void in 
     do 
     { 
      let jsonResult : NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary 
      print("Birthdate : \(jsonResult.valueForKey("birthday"))") 
     } 
     catch 
     { 
      print(error) 
     } 
    } 
関連する問題