简体   繁体   中英

Migration from AlchemyNews to Watson Discovery gives 401 error in Swift V3 com.ibm.watson.developer-cloud.DiscoveryV1 Code=401

Hello I have moved over from AlchemyAPI to DiscoveryV1 but my swift program is getting a 401 error, rror Domain=com.ibm.watson.developer-cloud.DiscoveryV1 Code=401 "Not Authorized" UserInfo={NSLocalizedFailureReason=Not Authorized}

The app was working fine before moving to Discovery and the Bluemix support team have verified the credentials and get no error when running the query in BLuemix

for the sake of it I also added the url into the App transport Security settings which was a guess but it didn't change the error I have added aa screen capture of the App Transport settings

here are the credentials I am using let wdn = Discovery(username: "my-user-name", password: "my-password", version: "2017-03-08")

let environmentID = "envID generated under my account on bluemix"
let collectionID = "collectionID generated under my account on bluemix"
let filter = ""
let query = newsSearchString < variable set later
let aggregation = "term(enriched_text.concepts.text).top_hits(10)"
let numberOfItemsToReturn = 30
let failure = { (error: Error) in print(error) }
let returnEntities = "enriched.url.url,enriched.url.title,enriched.url.author"




[enter image description here][1]


  [1]: https://i.stack.imgur.com/5UvJO.png

I created a new app + service, and did not get an unauthorized error. Here are the steps I followed:

码 应用传输安全设置

  1. I downloaded the Watson Conversation starter from Bluemix . This includes a lightweight Watson project which includes the SDKs and settings necessary to get set up quickly (essentially all you have to do is put your credentials in a config file for the Converation service).

  2. Because that starter has all of the Watson configuration set up, I just imported the DiscoveryV1 service, dragged the Framework over to my project (updated the Build Phase), and typed in the initialization snippet and everything is working for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM