环顾四周,特别是关注Pinterest API文档,我认为我已经正确设置了所有内容,但在我尝试登录时仍然获得error NSError: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)"
。授予SDK文档在Objective-C中,但我认为我的Swift转换看起来不错?我唯一能想到的是,他们必须批准他们的APP ID?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
PDKClient.configureSharedInstanceWithAppId("XXX")
return true
}
func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool {
let pdkClient: PDKClient = PDKClient.sharedInstance()
return pdkClient.handleCallbackURL(url)
}
PDKClient.sharedInstance().getAuthenticatedUserPinsWithFields(Set(["id", "image", "note"]), success:
{ (pdk :PDKResponseObject!) -> Void in
print("success /(pdk)")
}) { (err :NSError!) -> Void in
print("error NSError: \(err)")
}
<key>LSApplicationQueriesSchemes</key>
<array>
<string>pinterestsdk.v1</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>pinit</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
答案 0 :(得分:1)
我想我错过了info.plist中的另一个密钥,我添加了以下内容(我在SDK的示例应用程序中找到)并且我现在正在成功进行身份验证:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>pdkXXX</string>
</array>
</dict>
</array>
答案 1 :(得分:-1)
在调用getAuthenticatedUserPinsWithFields方法之前,请确保您具有适当的权限。
if(PDKClient.sharedInstance().authorized == false)
{
PDKClient.sharedInstance().authenticateWithPermissions([PDKClientReadPrivatePermissions,PDKClientReadPublicPermissions,PDKClientReadRelationshipsPermissions,PDKClientWritePublicPermissions,PDKClientWritePrivatePermissions,PDKClientWriteRelationshipsPermissions], withSuccess: { (response : PDKResponseObject!) -> Void in
// call getAuthenticatedUserPinsWithFields method here
}, andFailure: { (error : NSError!) -> Void in
print(error.description)
})
}