当我在 Parse Swift 2.2 中遇到未经授权的错误时该怎么办

What to do when I get the unauthorized error in Parse Swift 2.2

我正在使用空白应用 Parse 下载和 back4app。我将客户端和应用程序 ID 放在 AppDelegate 和 运行 应用程序上,但出现以下错误:

"2016-07-26 11:08:29.681 ParseStarterProject-Swift[1464:107722] [Error]: unauthorized (Code: 0, Version: 1.12.0) 2016-07-26 11:08:29.682 ParseStarterProject-Swift[1464:107719] [Error]: Failed to run command eventually with error: Error Domain=Parse Code=0 "unauthorized" UserInfo={error=unauthorized, NSLocalizedDescription=unauthorized, temporary=0}"

ViewController为空

AppDelegate:

import UIKit

import Parse

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Enable storing and querying data from Local Datastore.
    // Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
    Parse.enableLocalDatastore()
     Parse.setApplicationId("ciBn93EohqEq7WLJEAByrrVFfR6B3Fu98UJgRteY",clientKey: "KHKJgfJhSLAktjqmKHRhlaUtBhtzZELsdwexpIdf")

    PFUser.enableAutomaticUser()

    let defaultACL = PFACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.publicReadAccess = true

    PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true)

    if application.applicationState != UIApplicationState.Background {
        // Track an app open here if we launch with a push, unless
        // "content_available" was used to trigger a background push (introduced in iOS 7).
        // In that case, we skip tracking here to avoid double counting the app-open.

        let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
        let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
        var noPushPayload = false;
        if let options = launchOptions {
            noPushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil;
        }
        if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
            PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        }
    }

    return true
}

//--------------------------------------
// MARK: Push Notifications
//--------------------------------------

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let installation = PFInstallation.currentInstallation()
    installation.setDeviceTokenFromData(deviceToken)
    installation.saveInBackground()

    PFPush.subscribeToChannelInBackground("") { (succeeded: Bool, error: NSError?) in
        if succeeded {
            print("ParseStarterProject successfully subscribed to push notifications on the broadcast channel.\n");
        } else {
            print("ParseStarterProject failed to subscribe to push notifications on the broadcast channel with error = %@.\n", error)
        }
    }
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    if error.code == 3010 {
        print("Push notifications are not supported in the iOS Simulator.\n")
    } else {
        print("application:didFailToRegisterForRemoteNotificationsWithError: %@\n", error)
    }
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    PFPush.handlePush(userInfo)
    if application.applicationState == UIApplicationState.Inactive {
        PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
    }
}
}

谢谢

我想你的appid和客户端密钥一定有问题。

I find what should you do,it's just change

This

 Parse.setApplicationId("APP_ID",clientKey: "CLIENT_KEY")

With this

let configuration = ParseClientConfiguration{
        [=11=].applicationId = "APP_ID"
        [=11=].clientKey = "CLIENT_KEY"
        [=11=].server = "https://parseapi.back4app.com/"
    }

服务器地址还是一样