2016-07-10 18 views
0

即時得到這個錯誤,而張貼圖像Pinterest的斯威夫特/ iOS的:錯誤後圖像Pinterest的

Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x144603bd0> { URL: https://api.pinterest.com/v1/pins/ } { status code: 401, headers { 
    "Accept-Ranges" = bytes; 
    "Cache-Control" = private; 
    Connection = close; 
    "Content-Length" = 177; 
    "Content-Type" = "application/json"; 
    Date = "Sun, 10 Jul 2016 19:38:00 GMT"; 
    "Pinterest-Generated-By" = "devplatform-devapi-prod-de3d740a"; 
    "Pinterest-Version" = bcdafd3; 
    Server = nginx; 
    "X-Content-Type-Options" = nosniff; 
    "X-Pinterest-RID" = 480720869025; 
    "X-Varnish" = 2958547338; 
} }, NSErrorFailingURLKey=https://api.pinterest.com/v1/pins/, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a2022 6661696c 75726522 2c202263 6f646522 3a20332c 2022686f 7374223a 20226465 76706c61 74666f72 6d2d6465 76617069 2d70726f 642d6465 33643734 3061222c 20226765 6e657261 7465645f 6174223a 20225375 6e2c2031 30204a75 6c203230 31362031 393a3338 3a303020 2b303030 30222c20 226d6573 73616765 223a2022 41757468 6f72697a 6174696f 6e206661 696c6564 2e222c20 22646174 61223a20 6e756c6c 7d>, NSLocalizedDescription=Request failed: unauthorized (401)} 

這裏是我的代碼:

PDKClient.sharedInstance().createPinWithImage(image, link: NSURL(string:"http://domain"), onBoard: "MyBoard", description: caption, progress: {percent in 
      print(percent) 
      }, withSuccess: {PDKResponseObject in 
       print("ok") 
       print(PDKResponseObject.boards()) 
      }, andFailure: {error in 
       print(error) 
     }) 
+0

您可以分享如何撥打此電話 –

+0

向我們顯示網址。 –

+0

@AlvinVarghese我更新了代碼 – TomSawyer

回答

0

401錯誤是指下列情況之一。

1.Authentication failed. 
2.Authorization failed. 
3.You are not permitted to access that resource. 

仔細檢查您的權限,檢查您的會話令牌是否過期。

所以我認爲你的代碼或請求沒有問題。這是您在Pinterest應用中擁有的權限。

嘗試將請求URL從http更改爲https

檢查您發送給Pinterest的參數,檢查parameter names是否正確,如Pinterest文檔中所述。這些參數也有適當的數據類型,我的意思是不通過String代替Integer的值。 。

+0

我知道401錯誤的含義。我已經閱讀過Pinterest SDK的SDK'注意:如果你只是想Pin,就沒有必要進行身份驗證!您可以使用CreatePin方法來進行無需驗證的Pin。此方法將用戶重定向到Pinterest應用並顯示Pin創建窗口。如果你想要一個定製的體驗,用戶在不離開你的應用的情況下進行固定,你需要進行身份驗證。「因此,如果我想固定圖像,則不需要驗證任何內容。 – TomSawyer

+0

並且該鏈接可以是任何有效的網址,我試圖改變爲「https:// www.pinterest.com」,但它不起作用,或者是 – TomSawyer

+0

嗯。真奇怪。 –