[GH-ISSUE #92] Yelp: Missing oauth_consumer_key? #60

Closed
opened 2026-03-03 16:45:18 +03:00 by kerem · 1 comment
Owner

Originally created by @sephethus on GitHub (Aug 14, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/92

Yelp stopped working for me suddenly. I was going straight to the OAuthSwiftClient to initialize it and it was working great for some time. Now it's stopped. I can trace the headers that contain them all the way to the makeRequest method in OAuthSwiftHTTPRequest.swift file. Then I lose them. Where did they go? When I println them here they are still there and contain the keys.

    public class func makeRequest(        URL: NSURL,
        method: String,
        headers: [String : String],
        parameters: Dictionary<String, AnyObject>,
        dataEncoding: NSStringEncoding,
        encodeParameters: Bool,
        error: NSErrorPointer,
        body: NSData? = nil,
        contentType: String? = nil) -> NSMutableURLRequest? {

            var request = NSMutableURLRequest(URL: URL)
            request.HTTPMethod = method

            println(headers) //this works and shows all my keys************



            //if let cs =

            let charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(dataEncoding))

            var nonOAuthParameters = parameters.filter { key, _ in !key.hasPrefix("oauth_") }


            if (body != nil && contentType != nil) {
                request.setValue(contentType!, forHTTPHeaderField: "Content-Type")
                //request!.setValue(self.HTTPBodyMultipart!.length.description, forHTTPHeaderField: "Content-Length")
                request.HTTPBody = body!
            } else {
                if nonOAuthParameters.count > 0 {
                    if request.HTTPMethod == "GET" || request.HTTPMethod == "HEAD" || request.HTTPMethod == "DELETE" {
                        let queryString = nonOAuthParameters.urlEncodedQueryStringWithEncoding(dataEncoding)
                        request.URL = URL.URLByAppendingQueryString(queryString)
                        request.setValue("application/x-www-form-urlencoded; charset=\(charset)", forHTTPHeaderField: "Content-Type")
                    }
                    else {
                        if (encodeParameters) {
                            let queryString = nonOAuthParameters.urlEncodedQueryStringWithEncoding(dataEncoding)
                            //request.URL = URL.URLByAppendingQueryString(queryString)
                            request.setValue("application/x-www-form-urlencoded; charset=\(charset)", forHTTPHeaderField: "Content-Type")
                            request.HTTPBody = queryString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)

                        }
                        else {
                            var jsonError: NSError?
                            if let jsonData: NSData = NSJSONSerialization.dataWithJSONObject(nonOAuthParameters, options: nil, error: &jsonError)  {
                                request.setValue("application/json; charset=\(charset)", forHTTPHeaderField: "Content-Type")
                                request.HTTPBody = jsonData

                            }
                            else {
                                if (error != nil) {
                                    //println(jsonError!.localizedDescription)
                                    error.memory = jsonError
                                }
                                return nil
                            }
                        }
                    }
                }
            }
            return request
    }
Originally created by @sephethus on GitHub (Aug 14, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/92 Yelp stopped working for me suddenly. I was going straight to the OAuthSwiftClient to initialize it and it was working great for some time. Now it's stopped. I can trace the headers that contain them all the way to the makeRequest method in OAuthSwiftHTTPRequest.swift file. Then I lose them. Where did they go? When I println them here they are still there and contain the keys. ``` public class func makeRequest( URL: NSURL, method: String, headers: [String : String], parameters: Dictionary<String, AnyObject>, dataEncoding: NSStringEncoding, encodeParameters: Bool, error: NSErrorPointer, body: NSData? = nil, contentType: String? = nil) -> NSMutableURLRequest? { var request = NSMutableURLRequest(URL: URL) request.HTTPMethod = method println(headers) //this works and shows all my keys************ //if let cs = let charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(dataEncoding)) var nonOAuthParameters = parameters.filter { key, _ in !key.hasPrefix("oauth_") } if (body != nil && contentType != nil) { request.setValue(contentType!, forHTTPHeaderField: "Content-Type") //request!.setValue(self.HTTPBodyMultipart!.length.description, forHTTPHeaderField: "Content-Length") request.HTTPBody = body! } else { if nonOAuthParameters.count > 0 { if request.HTTPMethod == "GET" || request.HTTPMethod == "HEAD" || request.HTTPMethod == "DELETE" { let queryString = nonOAuthParameters.urlEncodedQueryStringWithEncoding(dataEncoding) request.URL = URL.URLByAppendingQueryString(queryString) request.setValue("application/x-www-form-urlencoded; charset=\(charset)", forHTTPHeaderField: "Content-Type") } else { if (encodeParameters) { let queryString = nonOAuthParameters.urlEncodedQueryStringWithEncoding(dataEncoding) //request.URL = URL.URLByAppendingQueryString(queryString) request.setValue("application/x-www-form-urlencoded; charset=\(charset)", forHTTPHeaderField: "Content-Type") request.HTTPBody = queryString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true) } else { var jsonError: NSError? if let jsonData: NSData = NSJSONSerialization.dataWithJSONObject(nonOAuthParameters, options: nil, error: &jsonError) { request.setValue("application/json; charset=\(charset)", forHTTPHeaderField: "Content-Type") request.HTTPBody = jsonData } else { if (error != nil) { //println(jsonError!.localizedDescription) error.memory = jsonError } return nil } } } } } return request } ```
kerem closed this issue 2026-03-03 16:45:18 +03:00
Author
Owner

@sephethus commented on GitHub (Aug 14, 2015):

Nevermind I edited out the for loop. Closing this.

<!-- gh-comment-id:131238959 --> @sephethus commented on GitHub (Aug 14, 2015): Nevermind I edited out the for loop. Closing this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#60
No description provided.