GarySabo GarySabo - 6 months ago 112
Swift Question

Does Pinterest need to authorize an App ID prior to OAuth working?

Looking around and especially following the Pinterest API docs, I think I've set everything up correctly, but still get

error NSError: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)"
when I try to log in. Granted the SDK docs are in Objective-C, but I think my Swift conversion looks ok? The only thing I can think of is that they have to approve the APP ID on their end maybe?

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>

Answer

I think I was missing another key in my info.plist, I added the below (that I found in the SDK's example app) and I'm authenticating successfully now:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string></string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>pdkXXX</string>
            </array>
        </dict>
    </array>