Yelp API OAuth - oauth_signature

流过昼夜 提交于 2019-12-10 22:53:40

问题


I am trying to use the Yelp API in a Swift iOS app, but am new to encryption. I understand that I am supposed to encrypt the signature with SHA1, but can't find good resources for doing this in Swift/Xcode.

Additionally, the Yelp docs say I am supposed to pass the signature value as "The generated request signature, signed with the oauth_token_secret obtained". I don't understand what is meant by "signed with". Link to the docs here: Yelp Authentication

Any help would be hugely appreciated.


回答1:


Update: Take a look at CocoaPods YELP solutions, you have options of using a CocoaPod, directly embedding the code or just using the code as an example.

Another way to go is CocoaPods OAuth.

SHA1 is not encryption, it is a hash function that creates a 20-byte signature for it's input.

Here is an example that may be useful but may not meet your inpout and output data formats:

func sha1(string string: String) -> [UInt8] {
    var digest = [UInt8](count: Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: 0)
    if let data = string.dataUsingEncoding(NSUTF8StringEncoding) {
        CC_SHA1(data.bytes, CC_LONG(data.length), &digest)
    }
    return digest
}

// Test:

let digest = sha1(string:"Here is the test string")
print("digest: \(digest)")

Output:

digest: [143, 131, 57, 51, 3, 161, 81, 234, 51, 191, 110, 62, 187, 194, 133, 148]



来源:https://stackoverflow.com/questions/34189829/yelp-api-oauth-oauth-signature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!