2015-10-18 36 views
2

我創建了一個swift代碼,使用facebook SDK 4.x.代碼使用FBSDKShareButton並且工作得很好。 這是代碼:Swift - 直接在Facebook上發佈

let content : FBSDKShareLinkContent = FBSDKShareLinkContent() 
      content.contentURL = NSURL(string: "http://alexandreccarmo.com") 
      content.contentTitle = "Teste" 
      content.contentDescription = "teste teste" 
      content.imageURL = NSURL(string: "xxxx/2.jpg") 


      let button : FBSDKShareButton = FBSDKShareButton() 
      button.shareContent = content 
      button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 25) 
      self.view.addSubview(button) 

但我需要在不使用Facebook對話交流。當用戶點擊我的應用程序的按鈕時,我需要直接在他們的Facebook上分享。 我嘗試這樣做:

let contentx : FBSDKShareLinkContent = FBSDKShareLinkContent() 
      contentx.contentURL = NSURL(string: "http://alexandreccarmo.com") 
      contentx.contentTitle = "Testexxxxx" 
      contentx.contentDescription = "teste testexxx" 
      contentx.imageURL = NSURL(string: "xxxx/2.jpg") 

      FBSDKShareAPI.shareWithContent(contentx, delegate: nil) 

但我收到此錯誤:

FacebookLogin [6721:3464359] FBSDKLog:警告:[FBSDKAccessToken currentAccessToken]缺少publish_actions權限

我在Facebook上閱讀當我需要發送共享時,我需要請求「publish_actions」的開發人員。但我不明白我該怎麼做。有人知道嗎?

回答

1

因此,這裏是一些代碼,我曾經發表在Facebook上的影像,無需將Facebook的SDK:

func actionTapped(sender: AnyObject) { 

    let objectsToShare = //reference to image 
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) 
    activityVC.completionWithItemsHandler = actionCompleted 
    presentViewController(activityVC, animated: true, completion: nil) 
} 

func actionCompleted(activityType: String!, completed: Bool, returnedItems: [AnyObject]!, error: NSError!) { 
    // Return if cancelled 
    if (!completed) { 
     return 
    } 
    close() 
} 

您可以檢查這些鏈接,以及:

  1. Can I use UIActivityViewController to share on Facebook ?
  2. http://roadfiresoftware.com/2014/02/how-to-add-facebook-and-twitter-sharing-to-an-ios-app/

我希望這有助於。

+1

我找到了方法: https://developers.facebook.com/docs/ios/graph#posting –