2011-03-08 135 views
4

我正在开发C#应用程序,它管理Facebook上使用Facebook C#SDK的粉丝页面。我遇到了两个问题,一个是在墙上发布消息,另一个是在粉丝页上创建事件。发布在Facebook页面作为页面不作为管理员用户使用Facebook C#SDK

是否可以在粉丝页面墙上作为粉丝页面发布消息而不是管理员用户?

我可以编程方式使用Facebook C#SDK在粉丝页面上创建事件(而不是作为管理员,但作为粉丝页面)?

我经历了其他一些SDK的其他教程,如Facebook PHP SDK。 PHP SDK允许将事件创建为粉丝页面,但对于C#SDK,创建事件不会给出任何结果。

+0

一个似乎有事件已被回答:) http://stackoverflow.com/questions/4925705/how-to-programmatically-add-an-event-to-a-page-using-graph-api/4926393#4926393 – VorTechS 2011-03-08 15:38:39

回答

1

要发布消息,您需要授予manages_pages权限,并使用“/ me/accounts”的结果从Fan页面的帐户获取访问令牌。

下面是我用张贴消息本身的粉丝专页:

      var dicParams = new Dictionary<string, object>(); 
         dicParams["message"] = stSmContentTitle; 
         dicParams["caption"] = string.Empty; 
         dicParams["description"] = string.Empty; 
         dicParams["name"] = smContent.CmeUrl; 
         dicParams["req_perms"] = "publish_stream"; 
         dicParams["scope"] = "publish_stream"; 

         // Get the access token of the posting user if we need to 
         if (destinationID != this.FacebookAccount.UserAccountId) 
         { 
          dicParams["access_token"] = this.getPostingUserAuthToken(destinationID); 
         } 
         publishResponse = this.FacebookConnection.Post("/" + destinationID + "/feed", dicParams); 
+0

如何你是否“授予每个管理页面任务”? – camainc 2011-09-30 15:23:13

+0

@camainc - 首先确保您在Facebook上以您将用于墙上贴的身份登录。然后在浏览器中使用此网址:https://www.facebook.com/dialog/oauth?client_id=[APPID]&redirect_uri=[YOUR网站网址]&scope = offline_access,publish_stream&response_type = token'。一旦您在FCBK对话框中允许,您将被重定向到您在上面添加了令牌的[[Your SITE URL]]部分中使用的URL(请参阅浏览器的地址栏)。请注意这里的权限'offline_access',这将确保你的令牌不会过期。 – 2011-11-11 16:26:23

7

好吧,我只是碰到了这个同样的事情。出于我的目的,我正在授权应用程序作为粉丝页面发布到FB粉丝页面。所以我可以让多个用户访问该应用程序,但不能访问粉丝页面,以粉丝页面的形式发布。它符合我的要求。

无论如何,这里是我如何使用C#Facebook SDK Beta V5.0.9。 第一步,确保您试图发布的用户帐户能够发布到粉丝页面,并有权从应用程序中这样做。

其中大部分类似于VorTechS的帖子,只是稍微澄清一下。

Dictionary<string,string> fbParams = new Dictionary<string,string>(); 
       fbParams["message"] = Title; 
       fbParams["caption"] = string.Empty; 
       fbParams["description"] = string.Empty; 
       fbParams["req_perms"] = "publish_stream"; 
       fbParams["scope"] = "publish_stream"; 
       //Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users 
       FacebookWebClient fbClient = new FacebookWebClient(<YOUR_ACCOUNT_ACCESS_TOKEN>); 
       //Get the listing of accounts associated with the user 
       dynamic fbAccounts = fbClient.Get("/me/accounts"); 

       //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID) 
       foreach (dynamic account in fbAccounts.data) { 
        if (account.id == <DESTINATION_ID_OF_YOUR_FAN_PAGE>) { 
         //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out. 
         fbParams["access_token"] = account.access_token; 
         break; 
        } 
       } 
       //Then pass your destination ID and target along with FB Post info. You're Done. 
       dynamic publishedResponse = fbClient.Post("/" + <DESTINATION_ID_OF_YOUR_FAN_PAGE> + "/feed", fbParams); 
1

我想感谢您的回复,这真的很有帮助。对我而言,它仍然在我的Facebook页面上发布为ME(而不是页面)。我认为这只是我得到令牌的方式。虽然,foreach循环不适合我。所以,我这样做:

public void postFacebook(object sender, EventArgs e) 
{ 
    //You will get your "myAccessToken" at this adress: 
    //https://www.facebook.com/dialog/oauth?client_id=<YOUR_APP_ID>&redirect_uri=<THE_PAGE_YOU_WILL_RECEIVE_YOUR_TOKEN_AT>&scope=offline_access,manage_pages,publish_stream&response_type=token 
    string myAccessToken = "<IN_THE_RETURNED_URL_BELOW>"; 
    string myPageId = "<YOUR_FAN_PAGE_ID>"; 

    Dictionary<string,string> fbParams = new Dictionary<string,string>(); 
    fbParams["message"] = "Testing 1 2 test"; 
    fbParams["caption"] = string.Empty; 
    fbParams["description"] = string.Empty; 
    fbParams["req_perms"] = "publish_stream"; 
    fbParams["scope"] = "publish_stream"; 
    //Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users 
    Facebook.FacebookAPI fbClient = new Facebook.FacebookAPI(myAccessToken); 
    //Get the listing of accounts associated with the user 
    var fbAccounts = fbClient.Get("/me/accounts"); 

    //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID) 
    foreach (var account in fbAccounts.Dictionary["data"].Array) 
    { 
     if (account.Dictionary["id"].String == myPageId) 
     { 
      //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out. 
      fbParams["access_token"] = account.Dictionary["access_token"].String; 

      //Update the Access token (to post as the page). If you don't it will post as YOUR personal name. 
      fbClient.AccessToken = fbParams["access_token"]; 
      break; 
     } 
    } 



    //Then pass your destination ID and target along with FB Post info. You're Done. 
    dynamic publishedResponse = fbClient.Post("/" + myPageId + "/feed", fbParams); 
} 

顺便问一下,你会需要这个SDK:SDK

1
在MVC4和C#SDK

,这让我的目标

[FacebookAuthorize("publish_stream")] 
    public ActionResult PostNotification(FacebookContext context) 
    { 
     var dicParams = new Dictionary<string, object>(); 
     dicParams["message"] = "đang tập code cho facebook [email protected]@"; 
     dicParams["caption"] = "bbbbb"; 
     dicParams["description"] = "cccccc"; 
     dicParams["name"] = "http://www.facebook.com"; 
     dicParams["req_perms"] = "publish_stream"; 
     dicParams["scope"] = "publish_stream"; 
     string destinationID = context.UserId; 
     context.Client.Post("/" + destinationID + "/feed", dicParams); 
     return RedirectToAction("Index"); 
    } 
相关问题