- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 native URL 和 URLRequest 类从 iOS 客户端检索 OAuth token 以使用 Yelp 的 Fusion API,但它在“tokenInfo”变量中给我这个错误:
client_id or client_secret parameters not found. Make sure to provide
client_id and client_secret in the body with the
application/x-www-form-urlencoded content-type
这是我的代码:
func getToken(){
var yelpTokenEndpoint = "https://api.yelp.com/oauth2/token"
var tokenURL = URL(string: yelpTokenEndpoint)
let requestJSON: [String:String] = ["client_id":"Not showing actual client id", "client_secret":"Not Gonna Show My Actual Client Secret either","grant_type":"client_credentials"]
let requestData = try? JSONSerialization.data(withJSONObject: requestJSON)
print(try? JSONSerialization.jsonObject(with: requestData!, options: []))
var tokenURLRequest = URLRequest(url: tokenURL!)
tokenURLRequest.httpMethod = "POST"
tokenURLRequest.httpBody = requestData!
tokenURLRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
let tokenSession = URLSession.shared
let tokenTask = tokenSession.dataTask(with: tokenURLRequest) { (data, response, error) in
if error != nil {
print("error getting your access token")
print(error!.localizedDescription)
}
if let data = data{
do{
if let tokenInfo = try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any]{
let token: String = tokenInfo["access_token"] as! String
print(token)
}
} catch {
print("Error converting to JSON")
}
}
}
tokenTask.resume()
}
是的,我确信我输入了正确的客户端凭据。非常感谢任何帮助,谢谢!
最佳答案
试试这个....
let clientId = "client_id"
let clientSecret = "client_secret"
let tokenURL = "https://api.yelp.com/oauth2/token"
let grantType = "client_credentials"
let url = NSURL(string: tokenURL as String );
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let request = NSMutableURLRequest(URL: NSURL(string: tokenURL)!)
request.HTTPMethod = "POST";
request.HTTPShouldHandleCookies = true
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let postString = "client_id=" + clientId + "&client_secret=" + clientSecret + "&grant_type=" + grantType
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if let data = data {
let response = NSString(data: data, encoding: NSUTF8StringEncoding)
print(response)
}
}
task.resume()
关于iOS Yelp OAuth token 检索,URLRequest 返回“未找到 client_id 或 client_secret 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42454542/
我正在尝试在 here 上可用的 google drive 的命令行演示应用程序.我已按照在 google api 控制台中创建新项目的所有步骤进行操作,然后下载了 client_secret.jso
我使用 ADAL for android 编写了下面的身份验证代码: mAuthContext = new AuthenticationContext(MainActivity.this, Const
对于用户身份验证,我使用最新的@azure/msal-angular 包。这个 Angular 库基于用于 AD 身份验证的最新 MSAL 库。但是库会抛出以下错误: ServerError: inv
我正在尝试回收 AKS 集群中的 service_principal:client_secret 值,该值是由 terraform 使用 azurerm_kubernetes_cluster 上的文档
我有以下代码: - (IBAction)connectToGoogleAnalyticsPressed:(id)sender { GPPSignIn *signIn = [GPPSignIn
我正在使用 PyDrive 将文件从我使用 Pyinstaller 打包的桌面 Python 应用程序上传到 GoogleDrive。我想尽可能地隐藏 client_secrets.json,所以我将
我尝试按照 https://developers.google.com/google-apps/activity/v1/quickstart/nodejs 中的说明使用 Node.js 创建示例程序
有点 OAUTH 的初学者,想问我是否理解正确。我正在使用 OWIN 和 C#,并设置以下场景: 用户向我的 token 端点发出请求,传入用户名/密码和密码 grant_type。如果凭据有效,那么
我正在使用 Python 中的 Google Tasks API 编写程序。我从 Google 下载并运行了示例应用程序,它带有一个名为 client_secrets.json 的文件。 .我知道该文
我目前的任务是弄清楚如何严格从客户端 JavaScript 充分利用 OAuth 2.0 提供程序,并且担心会暴露应用程序的 client_secret。这本质上是 OAuth 客户端的“密码”。 h
为了从 Facebook 获得 access_token,您必须传输您的 app_id、您在授权请求后收到的 code 以及您应用的 secret_key。 为什么我要EVER 传输我的 key ?这
我对这个东西很陌生,我真的不知道现在该怎么办,我需要能够输入“client_secret.json”文件的确切路径,但在每个教程中我看到它只使用中的文件名相同的目录,但我的不是。 creds = Se
我正在尝试从 google API 下载 client_secret.json。我正在执行 https://developers.google.com/gmail/api/quickstart/rub
我正在开发具有自己的 oAuth 授权的 Google chrome 扩展程序。当然,我必须使用 client_id 和 client_secret 作为请求 token 。 有什么办法可以向用户隐藏
我正在构建 Laravel 后端来验证来自移动设备的用户。并使用 https://github.com/lucadegasperi/oauth2-server-laravel 手机用户调用/oauth
阅读此处的一些答案,人们建议通过以下方式调用 Foursquare 进行无用户访问: https://api.foursquare.com/v2/venues/search?ll=40.7,-74&c
有没有什么巧妙的存储方法client_id和 client_secret安全地在客户端应用程序中? 这可能是一个被反编译的 Android/iOS 应用程序。或以纯文本形式提供的 Chrome 扩展程
我有一个可以在我的计算机上使用 dev_appserver.py 运行的应用程序。我部署成功: ronj@l:~$ appcfg.py update myapp/ 03:03 PM Host: app
我正在使用 google admin api 并将示例代码放在一起并稍作修改。我在谷歌端正确设置了东西,但是当我运行脚本时它一直给我错误。下面是我在 python 中的代码: from __futur
我正在尝试按照 Google 的 Node API 访问 gmail here . 当以 node quickstart.js 运行他们的示例快速入门时,出现以下错误: TypeError: Cann
我是一名优秀的程序员,十分优秀!