使用Swift从iOS应用程序发布到Facebook

使用Swift从iOS应用程序发布到Facebook,ios,facebook,swift,slrequest,Ios,Facebook,Swift,Slrequest,所以我已经调查了很长一段时间了,我已经决定联系群众 我知道,当通过iOS应用程序发布到Facebook时,该应用程序需要先读后写,即在发布到墙上之前先阅读用户的电子邮件。我知道这些权限列表不能在同一个请求中完成。所以我拼凑了如下代码 class func postToFacebook(message: String, appID: String){ var accountStore = ACAccountStore() var accountType = accountStor

所以我已经调查了很长一段时间了,我已经决定联系群众

我知道,当通过iOS应用程序发布到Facebook时,该应用程序需要先读后写,即在发布到墙上之前先阅读用户的电子邮件。我知道这些权限列表不能在同一个请求中完成。所以我拼凑了如下代码

class func postToFacebook(message: String, appID: String){

    var accountStore = ACAccountStore()
    var accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierFacebook)

    var optionsForPosting = [ACFacebookAppIdKey:appID, ACFacebookPermissionsKey: ["email"], ACFacebookAudienceKey: ACFacebookAudienceFriends]

    accountStore.requestAccessToAccountsWithType(accountType, options: optionsForPosting) {
        granted, error in
        if granted {

                var options = [ACFacebookAppIdKey:appID, ACFacebookPermissionsKey: ["publish_stream", "publish_actions"], ACFacebookAudienceKey: ACFacebookAudienceFriends]

                accountStore.requestAccessToAccountsWithType(accountType, options: options) {
                    granted, error in
                    if granted {
                        var accountsArray = accountStore.accountsWithAccountType(accountType)

                            if accountsArray.count > 0 {
                            var facebookAccount = accountsArray[0] as ACAccount

                            var parameters = Dictionary<String, AnyObject>()
                            parameters["access_token"] = facebookAccount.credential.oauthToken
                            parameters["message"] = message

                            var feedURL = NSURL(string: "https://graph.facebook.com/me/feed")

                            let posts = SLRequest(forServiceType: SLServiceTypeFacebook, requestMethod: SLRequestMethod.POST, URL: feedURL, parameters: parameters)

                            let handler: SLRequestHandler =  { (response, urlResponse, error) in
                                println(response)
                                println(urlResponse.statusCode)
                            }

                            posts.performRequestWithHandler(handler)
                        }
                    }
                    else{
                        println("Access denied")
                        println(error.localizedDescription)
                    }
                }
        }
        else{
            println("Access denied")
            println(error.localizedDescription)
        }
    }
}

我已经在Facebook开发网站上安装了我的应用程序,并且还向开发网站添加了正确的包标识符。

好的,所以答案是“发布流”似乎不作为权限使用,尽管有许多教程使用它。

您是否尝试过将您的FB应用程序id添加到plist

<key>FacebookAppID</key>
<string>101010101010</string>
<key>FacebookDisplayName</key>
<string>MyCoolProject</string>
FacebookAppID
101010101010
FacebookDisplayName
麦考尔项目

您可以从开发者网站获得FB应用程序id。

Eh否决票是怎么回事?这是一个真正的问题?我在这里遗漏了什么?!?!?如果这是一个骗局或明显的问题,我会删除这个问题,但如果能给你一点正确的暗示,我将不胜感激
<key>FacebookAppID</key>
<string>101010101010</string>
<key>FacebookDisplayName</key>
<string>MyCoolProject</string>