ios - Can any one tell me why i am getting Bad authentication error while executing this code(Swift)? -


i using fabric sdk add twitter login button in app....... add authentication header in url still showing bad authentication error while executing. suggest me how add header in url in swift.

     let twitter = twitter.sharedinstance()     let oauthsigning = twtroauthsigning(authconfig:twitter.authconfig, authsession:twitter.session())      let authheaders = oauthsigning.oauthechoheaderstoverifycredentials()      let request = nsmutableurlrequest(url: nsurl(string: "https://api.twitter.com/1.1/search/tweets.json?q=himan_dhawan")!)     request.allhttpheaderfields = authheaders     println(request)     var session = nsurlsession.sharedsession()      let task = session.datataskwithrequest(request, completionhandler: {data, response, error -> void in         if((error) != nil) {             println(error.localizeddescription)         }          var strdata = nsstring(data: data, encoding: nsasciistringencoding)         println(strdata)     })      task.resume() 

it's way you're setting headers on request.

the fabric doc's don't quite give full picture creating oauth signing headers when wanting use own nsmutableurlrequest.

let authheaders = oauthsigning.oauthechoheaderstoverifycredentials() 

the return [nsobject : anyobject]! dictionary gives values need request. however, provides headers different needs sent nsmutableurlrequest.

this how should setting headers request:

            let twitter = twitter.sharedinstance()              let oauthsigning = twtroauthsigning(authconfig:twitter.authconfig, authsession:twitter.session())              let authheaders = oauthsigning.oauthechoheaderstoverifycredentials()              let mutableurlwithusableurladdress = nsmutableurlrequest(url: usableurlforrequest)              mutableurlwithusableurladdress.addvalue(authheaders[twtroauthechoauthorizationheaderkey] as? string, forhttpheaderfield: "authorization") 

this sets required authorisation key value "authorization" header on request, opposed when pass in authheaders dictionary, gets set "x-verify-credentials-authorization".

the fabric doc's go this, it's more tucked away should be.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -