oAuth Instagram登录

时间:2016-04-29 15:23:12

标签: ios swift oauth-2.0 instagram-api

我正在尝试使用oAuth 2从Instagram获取访问令牌,以便在范围内使用它。我无法理解我应该如何配置" redirect_uri" (尝试了很多组合)如果我在原生应用中使用它,这意味着我不需要任何网站重定向,我需要在登录后重定向到应用程序本身。(也许我解释了一些不是正确的,因为不了解redirect_uri在本机应用程序中的工作方式)

AppDelegate.swift 中添加:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    if (url.host == "oauth-callback") {
        OAuthSwift.handleOpenURL(url)
    }
    return true
}

ViewController.swift

import UIKit
import OAuthSwift

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let oauthswift = OAuth2Swift(
            consumerKey:    "cc6dd7ca50c74f4f92a1a8328c9d4426",
            consumerSecret: "74f6bf3c839b4e15a747a332d#######",
            authorizeUrl:   "https://api.instagram.com/oauth/authorize",
            responseType:   "token"
        )
        oauthswift.authorizeWithCallbackURL(
            NSURL(string: "oauth-swift://oauth-callback/instagram")!,
            scope: "likes+comments", state:"INSTAGRAM",
            success: { credential, response, parameters in
                print(credential.oauth_token)
            },
            failure: { error in
                print(error.localizedDescription)
            }
        )

    }
}

(由于声誉,无法添加不带网址的图片):

Url schemes in project info

Instagram settings

问题:

  • 我做错了什么?

  • 如何修复它,以便应用可以打印(credential.oauth_token)"发生。

固定

NSURL(string: "oauth-swift://oauth-callback/instagram")!,

应改为

NSURL(string: "AppName://oauth-callback")!,

还有Instagram设置

0 个答案:

没有答案