Twitter的用戶詳細信息我想使用此代碼不能得到迅速
@IBAction func twitterLogin(sender: UIButton) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) {
let accountType = self.accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
accountStore.requestAccessToAccountsWithType(accountType, options: nil, completion: { (granted : Bool, error : NSError?) -> Void in
if error != nil {
print("Error in getting permission : \(error)")
} else {
if granted {
let accounts : NSArray = self.accountStore.accountsWithAccountType(accountType)
if accounts.count > 0 {
self.twitterAccount = accounts.lastObject as? ACAccount
let url = NSURL(string: "https://api.twitter.com/1.1/users/show.json")
let parameters : NSDictionary = ["fields": "user_id,screen_name"]
let twitterRequest : SLRequest = SLRequest(forServiceType: SLServiceTypeFacebook, requestMethod: SLRequestMethod.GET, URL: url, parameters: parameters as [NSObject : AnyObject])
twitterRequest.account = self.facebookAccount
twitterRequest.performRequestWithHandler({ (responseData : NSData?, urlResponse : NSHTTPURLResponse?, error : NSError?) -> Void in
if error != nil {
print("Error : \(error)")
} else {
// print("data : \(responseData)")
if let response = responseData {
var dict = NSDictionary()
do {
dict = try! NSJSONSerialization.JSONObjectWithData(response, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
} catch let error as NSError {
print("Error : \(error)")
}
print(dict)
}
}
})
}
} else {
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.showAlert(nil, message: "Permission not granted")
})
}
}
})
} else {
self.askForSettingsChange("No Twitter Account", message: "There are no Twitter accounts configured. You can add or create Twitter account in Settings")
}
}
輸出
{
errors = (
{
code = 215;
message = "Bad Authentication data.";
}
);
}
得到很多的例子來加載Twitter的用戶詳細信息,但不能得到妥善解決。
我認爲這可能是在API調用問題,或者可能是參數。
嘗試糾正,但沒有成功
好像你寫代碼爲Twitter和訪問Facebook帳戶。請檢查您的代碼。 SLServiceTypeFacebook = SLServiceTypeTwitter等 –