[GH-ISSUE #13] Example of one API call for each service #5

Closed
opened 2026-03-03 16:44:43 +03:00 by kerem · 7 comments
Owner

Originally created by @sumitk1 on GitHub (Dec 29, 2014).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/13

Hey @dongri. Awesome job making this example!
Can you include an example of one api call for each service?
e.g.

oauthswift.client.get("http://api.linkedin.com/v1/people/~?", parameters: parameters, success: { (data, response) -> Void in
            println("Succes") // or print some data from the profile
            }, failure: { (error) -> Void in
                println("Failed") // or reason what failed
        })

When I do the above for linkedIn I am getting Failure in the following function:

    func doOAuthLinkedin(){
        let oauthswift = OAuth1Swift(
            consumerKey:    Linkedin["consumerKey"]!,
            consumerSecret: Linkedin["consumerSecret"]!,
            requestTokenUrl: "https://api.linkedin.com/uas/oauth/requestToken",
            authorizeUrl:    "https://api.linkedin.com/uas/oauth/authenticate",
            accessTokenUrl:  "https://api.linkedin.com/uas/oauth/accessToken"
        )
        oauthswift.authorizeWithCallbackURL( NSURL(string: "oauth-swift://oauth-callback/linkedin")!, success: {
            credential, response in
            print("\n client oauth_token - " + credential.oauth_token)
            print("\n client oauth_token_secret - " + credential.oauth_token_secret)
            print("\n client consumer_key - " + credential.consumer_key)
            print("\n client consumer_secret - " + credential.consumer_secret)
            print("\n client oauth_verifier - " + credential.oauth_verifier)

        var parameters =  Dictionary<String, AnyObject>()
        parameters["oauth_nonce"] = "1234"
        oauthswift.client.get("http://api.linkedin.com/v1/people/~?", parameters: parameters, success: { (data, response) -> Void in
            println("Success")
            }, failure: { (error) -> Void in
                println("Failed")
        })
        self.performSegueWithIdentifier("jumpToUserTable", sender: self)

    }
Originally created by @sumitk1 on GitHub (Dec 29, 2014). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/13 Hey @dongri. Awesome job making this example! Can you include an example of one api call for each service? e.g. ``` oauthswift.client.get("http://api.linkedin.com/v1/people/~?", parameters: parameters, success: { (data, response) -> Void in println("Succes") // or print some data from the profile }, failure: { (error) -> Void in println("Failed") // or reason what failed }) ``` When I do the above for linkedIn I am getting Failure in the following function: ``` func doOAuthLinkedin(){ let oauthswift = OAuth1Swift( consumerKey: Linkedin["consumerKey"]!, consumerSecret: Linkedin["consumerSecret"]!, requestTokenUrl: "https://api.linkedin.com/uas/oauth/requestToken", authorizeUrl: "https://api.linkedin.com/uas/oauth/authenticate", accessTokenUrl: "https://api.linkedin.com/uas/oauth/accessToken" ) oauthswift.authorizeWithCallbackURL( NSURL(string: "oauth-swift://oauth-callback/linkedin")!, success: { credential, response in print("\n client oauth_token - " + credential.oauth_token) print("\n client oauth_token_secret - " + credential.oauth_token_secret) print("\n client consumer_key - " + credential.consumer_key) print("\n client consumer_secret - " + credential.consumer_secret) print("\n client oauth_verifier - " + credential.oauth_verifier) var parameters = Dictionary<String, AnyObject>() parameters["oauth_nonce"] = "1234" oauthswift.client.get("http://api.linkedin.com/v1/people/~?", parameters: parameters, success: { (data, response) -> Void in println("Success") }, failure: { (error) -> Void in println("Failed") }) self.performSegueWithIdentifier("jumpToUserTable", sender: self) } ```
kerem closed this issue 2026-03-03 16:44:43 +03:00
Author
Owner

@dongri commented on GitHub (Dec 30, 2014):

Hello @sumitk1
Added Linkedin Example
github.com/dongri/OAuthSwift@1eba2851d6
Using NSXMLParser if need...

<!-- gh-comment-id:68329113 --> @dongri commented on GitHub (Dec 30, 2014): Hello @sumitk1 Added Linkedin Example https://github.com/dongri/OAuthSwift/commit/1eba2851d62eee17779c470a0d0f0c52e795223c Using NSXMLParser if need...
Author
Owner

@sumitk1 commented on GitHub (Jan 2, 2015):

Hi @dongri this worked like a charm. Thanks for the help! I am using NSXMLParser for this as well.

<!-- gh-comment-id:68508344 --> @sumitk1 commented on GitHub (Jan 2, 2015): Hi @dongri this worked like a charm. Thanks for the help! I am using NSXMLParser for this as well.
Author
Owner

@realin commented on GitHub (Apr 8, 2016):

Hello @dongri
Can you guide me here, what i am doing wrong here.

`let oauthswift = OAuth1Swift(
consumerKey: "myKeyHere",
consumerSecret: "mySecretHere",
requestTokenUrl: "http://sitename/wc-api/v2/products",
authorizeUrl: "http://sitename/wc-api/v2/products",
accessTokenUrl: "http://sitename/wc-api/v2/products"
)
//oauthswift.authorize_url_handler = get_url_handler()
oauthswift.authorizeWithCallbackURL( NSURL(string: "sitename/wc-api/v2/products")!, success: {
credential, response, parameters in
// self.showTokenAlert(serviceParameters["name"], credential: credential)
self.testOauth(oauthswift)
}, failure: { error in
print(error.localizedDescription)
}
)

func testOauth(oauthswift: OAuth1Swift) {
    oauthswift.client.get("http://sitename/wc-api/v2/products", parameters: [:],
        success: {
            data, response in
            let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: [])

            print("jsonDict: \(jsonDict)")

        }, failure: { error in
            print(error)
    })
}`

I cannot get the data in jsonDict. It gives me this error:
HTTP Status 404: Not Found, Response:

{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}

Can you help me here.
Thanks

<!-- gh-comment-id:207392102 --> @realin commented on GitHub (Apr 8, 2016): Hello @dongri Can you guide me here, what i am doing wrong here. `let oauthswift = OAuth1Swift( consumerKey: "myKeyHere", consumerSecret: "mySecretHere", requestTokenUrl: "http://sitename/wc-api/v2/products", authorizeUrl: "http://sitename/wc-api/v2/products", accessTokenUrl: "http://sitename/wc-api/v2/products" ) //oauthswift.authorize_url_handler = get_url_handler() oauthswift.authorizeWithCallbackURL( NSURL(string: "sitename/wc-api/v2/products")!, success: { credential, response, parameters in // self.showTokenAlert(serviceParameters["name"], credential: credential) self.testOauth(oauthswift) }, failure: { error in print(error.localizedDescription) } ) ``` func testOauth(oauthswift: OAuth1Swift) { oauthswift.client.get("http://sitename/wc-api/v2/products", parameters: [:], success: { data, response in let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: []) print("jsonDict: \(jsonDict)") }, failure: { error in print(error) }) }` ``` I cannot get the data in jsonDict. It gives me this error: HTTP Status 404: Not Found, Response: {"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]} Can you help me here. Thanks
Author
Owner

@phimage commented on GitHub (Apr 8, 2016):

Your callback URL into authorizeWithCallbackURL is wrong and others also in init...

Why commenting an Old closed issue

<!-- gh-comment-id:207394885 --> @phimage commented on GitHub (Apr 8, 2016): Your callback URL into authorizeWithCallbackURL is wrong and others also in init... Why commenting an Old closed issue
Author
Owner

@phimage commented on GitHub (Apr 8, 2016):

Look into woocommerce oauth API to find the good urls

<!-- gh-comment-id:207395074 --> @phimage commented on GitHub (Apr 8, 2016): Look into woocommerce oauth API to find the good urls
Author
Owner

@realin commented on GitHub (Apr 8, 2016):

@phimage Can you guide me here, what should be the correct code?

<!-- gh-comment-id:207399221 --> @realin commented on GitHub (Apr 8, 2016): @phimage Can you guide me here, what should be the correct code?
Author
Owner

@phimage commented on GitHub (Apr 8, 2016):

Did you read my message, go to oauth Doc of woocommerce... I can help but not work for you, try by yourself...

<!-- gh-comment-id:207399541 --> @phimage commented on GitHub (Apr 8, 2016): Did you read my message, go to oauth Doc of woocommerce... I can help but not work for you, try by yourself...
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#5
No description provided.