无法迅速注销Pinterest

时间:2018-08-10 07:08:00

标签: ios arrays pinterest

我正在将Pinterest登录集成到我的swift应用中,但是问题是我完全登录成功,但是当我单击按钮注销时,我无法在此处注销我的代码

代码

    @IBAction func btnLogin(_ sender: UIButton) {
            PDKClient.sharedInstance().authenticate(withPermissions: [PDKClientReadPublicPermissions,PDKClientWritePublicPermissions,PDKClientReadRelationshipsPermissions,PDKClientWriteRelationshipsPermissions], withSuccess: { (PDKResponseObject) in


                self.accessToken = PDKClient.sharedInstance().oauthToken


                //MARK: - Getting User Profile, use "/v1/me" to get user data in the Response object -

                let parameters : [String:String] =
                    [

                        "fields":  "first_name,id,last_name,url,image,username,bio,counts,created_at,account_type" //these fields will be fetched for the loggd in user
                ]

                PDKClient.sharedInstance().getPath("/v1/me/", parameters: parameters, withSuccess: {

                    (PDKResponseObject) in
                    self.view.isUserInteractionEnabled = true

                     self.user = (PDKResponseObject?.user())!
                    print(PDKResponseObject!)
                    self.lblUserName.text = PDKResponseObject?.user().username
                    if let url = JSON(PDKResponseObject?.user().images["60x60"] as Any)["url"].string
                    {
                        self.imgProPic.sd_setImage(with: URL(string: url))
                    }

                }) {
                    (Error) in
                    if let error = Error
                    {
                        print("\(Error)")
                    }
                    self.view.isUserInteractionEnabled = true
                    PDKPinError.unknown
                }

            }) {
                (Error) in
                self.view.isUserInteractionEnabled = true

            }
        }
        @IBAction func btnLogout(_ sender: UIButton) {
       /*
            let cookieJar : HTTPCookieStorage = HTTPCookieStorage.shared
            for cookie in cookieJar.cookies! as [HTTPCookie]{
            NSLog("cookie.domain = %@", cookie.domain)

            if cookie.domain == "www.pinterest.com" ||
                cookie.domain == "api.pinterest.com"{

                cookieJar.deleteCookie(cookie)
            }
        }
       */
            PDKClient.clearAuthorizedUser()
        }

在这里,我完成了clearAuthorizedUser()但没有注销,并且我也完成了cookie清除代码,但是那没用,请帮助我解决这个问题

1 个答案:

答案 0 :(得分:1)

我遇到了一个非常相似的问题,我认为我可以通过在此处发布解决方案来帮助某人。我正在维护的应用通过在UIWebView中使用适当的参数加载“ https://api.pinterest.com/oauth/”来对Pinterest进行身份验证。这种身份验证方法不需要Pinterest SDK,并在此处进行了详细说明:https://developers.pinterest.com/docs/api/overview/。我能够添加一个按钮,用户可以点击该按钮以将其从经过身份验证的Pinterest帐户中注销。为了注销用户,我删除了与Pinterest身份验证关联的所有cookie,并删除了所有存储的身份验证令牌。以下是我用于删除Cookie的代码:

let cookieJar: HTTPCookieStorage = HTTPCookieStorage.shared
 if let cookies: [HTTPCookie] = cookieJar.cookies {
     for cookie in cookies {
         let domain = cookie.domain
         if domain == "accounts-oauth.pinterest.com"
                    || domain == ".pinterest.com"
                    || domain == ".facebook.com"
                    || domain == "accounts.google.com" {
             cookieJar.deleteCookie(cookie)
         }
     }
 }

此后,您很可能需要调用PDKClient.clearAuthorizedUser()来删除所有存储的身份验证令牌。