[GH-ISSUE #355] How to Get HTTP request JSON #224

Closed
opened 2026-03-03 16:46:49 +03:00 by kerem · 2 comments
Owner

Originally created by @megifernanda on GitHub (Apr 3, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/355

Description:

Hello sir, i already got Acces token from my API Login and then i want get data from API json with my acces token. so, how to use OAuth get request http method with OAuth and my acces token.

i have json parse standar without OAuth

            let url = NSURL(string: "http://getmydetails.pe.hu/test/parsejsonswift3.php")
            let request = NSMutableURLRequest(url: url! as URL)
            request.httpMethod = "GET"
            
            request.addValue("application/json", forHTTPHeaderField: "Authorization")
            
            let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in
                
                guard error == nil && data != nil else {
                    print("error", error!)
                    return
                }
                
                let httpStatus = response as? HTTPURLResponse
                
                if httpStatus!.statusCode == 200
                {
                    if data?.count != 0
                    {
                      let responString = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments)
                        print(responString)
                    }
                    else{
                        print("No got data from URL")
                    }
                }
                else
                {
                    print("error httpstatus code is ", httpStatus!.statusCode)
                }
            }
            
            task.resume()

so, where i can see about get http request with OAuth ?

thank you sir

OAuth Provider (Twitter, Github, ..):

8Villages

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 8.0 (Swift 3.0)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @megifernanda on GitHub (Apr 3, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/355 ### Description: Hello sir, i already got Acces token from my API Login and then i want get data from API json with my acces token. so, how to use OAuth get request http method with OAuth and my acces token. i have json parse standar without OAuth > let url = NSURL(string: "http://getmydetails.pe.hu/test/parsejsonswift3.php") let request = NSMutableURLRequest(url: url! as URL) request.httpMethod = "GET" request.addValue("application/json", forHTTPHeaderField: "Authorization") let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in guard error == nil && data != nil else { print("error", error!) return } let httpStatus = response as? HTTPURLResponse if httpStatus!.statusCode == 200 { if data?.count != 0 { let responString = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) print(responString) } else{ print("No got data from URL") } } else { print("error httpstatus code is ", httpStatus!.statusCode) } } task.resume() so, where i can see about get http request with OAuth ? thank you sir ### OAuth Provider (Twitter, Github, ..): 8Villages ### OAuth Version: - [x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [x] Carthage - [ ] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:46:50 +03:00
Author
Owner

@phimage commented on GitHub (Apr 3, 2017):

please read the readme.md

<!-- gh-comment-id:291148457 --> @phimage commented on GitHub (Apr 3, 2017): please read the readme.md
Author
Owner

@megifernanda commented on GitHub (Apr 4, 2017):

you mean this code ? and where i put my Acces Token, Consumer Key and Consumer Secret?

`oauthswift.client.get("https://api.linkedin.com/v1/people/~",

     success: { response in
    let dataString = response.string
    print(dataString)
  },
  failure: { error in
    print(error)
  }
  )`
<!-- gh-comment-id:291374141 --> @megifernanda commented on GitHub (Apr 4, 2017): you mean this code ? and where i put my Acces Token, Consumer Key and Consumer Secret? `oauthswift.client.get("https://api.linkedin.com/v1/people/~", success: { response in let dataString = response.string print(dataString) }, failure: { error in print(error) } )`
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#224
No description provided.