Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of one API call for each service #13

Closed
sumitk1 opened this issue Dec 29, 2014 · 7 comments
Closed

Example of one API call for each service #13

sumitk1 opened this issue Dec 29, 2014 · 7 comments

Comments

@sumitk1
Copy link

sumitk1 commented Dec 29, 2014

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)

    }
@dongri
Copy link
Member

dongri commented Dec 30, 2014

Hello @sumitk1
Added Linkedin Example
1eba285
Using NSXMLParser if need...

@sumitk1
Copy link
Author

sumitk1 commented Jan 2, 2015

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

@sumitk1 sumitk1 closed this as completed Jan 2, 2015
@realin
Copy link

realin commented 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

@phimage
Copy link
Member

phimage commented Apr 8, 2016

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

Why commenting an Old closed issue

@phimage
Copy link
Member

phimage commented Apr 8, 2016

Look into woocommerce oauth API to find the good urls

@realin
Copy link

realin commented Apr 8, 2016

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

@phimage
Copy link
Member

phimage commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants