【发布时间】:2016-03-20 10:46:44
【问题描述】:
我有一个应用程序(ios),你可以用谷歌登录,我要求用户授予访问他的 youtube 数据的权限,
func doOAuthGoogle(){
let oauthswift = OAuth2Swift(
consumerKey: GoogleYoutube["consumerKey"]!,
consumerSecret: GoogleYoutube["consumerSecret"]!,
authorizeUrl: "https://accounts.google.com/o/oauth2/auth",
accessTokenUrl: "https://accounts.google.com/o/oauth2/token",
responseType: "code"
)
oauthswift.authorizeWithCallbackURL( NSURL(string: "W2GCW24QXG.com.xxx.xxx:/oauth-swift")!, scope: "https://www.googleapis.com/auth/youtube", state: "", success: {
credential, response, parameters in
print("oauth_token:\(credential.oauth_token)")
let parameters = Dictionary<String, AnyObject>()
//TODO: send oauth to server
Alamofire.request(.GET, "http://xxx.azurewebsites.net:80/api/Login/Google/", parameters: ["access_token" : credential.oauth_token]).responseJSON { response in
print(response)
let resultDic : NSDictionary = (response.result.value as? NSDictionary)!
defaults.setObject(resultDic.valueForKey("userId"), forKey: "UserId")
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("vcGroupsViewController") as? GroupsController
self.navigationController?.pushViewController(vc!, animated: true)
}
}, failure: {(error:NSError!) -> Void in
print("ERROR: \(error.localizedDescription)")
})
}
之后我得到credential.oauth_token 并将其发送到.NET 的服务器。
在服务器上我有图书馆
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
现在我想获取用户音乐播放列表,但我找不到示例代码,例如在具有 facebookclient 的 facebook 中
var accessToken = access_token;
var client = new FacebookClient(accessToken);
// 1 : hit graph\me?fields=
dynamic me = client.Get("me", new { fields = new[] { "id", "name", "first_name", "last_name", "picture.type(large)", "email", "updated_time" } });
dynamic meMusic = client.Get("me/music");
【问题讨论】:
标签: c# ios .net youtube youtube-api