【发布时间】:2015-12-28 23:18:32
【问题描述】:
我正在尝试从我自己的 iOS 访问 Instagram 应用程序以进行 OAuth 注册。我有以下代码,它正在通过 Safari 访问 Instagram,但如果它在手机上,我希望打开该应用程序。还在寻找一种从 Instagram 为我的应用获取身份验证令牌的方法。
这是我的代码:
func startOAuth2Login()
{
....
let authPath:String = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=grokInstagram://?aParam=paramVal&response_type=code"
var instagramHooks = "instagram://app"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
{
UIApplication.sharedApplication().openURL(instagramUrl!)
} else {
//redirect to safari because the user doesn't have Instagram
print("didn't have it")
UIApplication.sharedApplication().openURL(NSURL(string: authPath)!)
}
....
【问题讨论】:
标签: ios oauth swift2 instagram-api