2

Facebook SDKをインストールしました

今、私は以下のコードでこのように壁に投稿することができます

ここに画像の説明を入力

上記のメッセージを投稿するためのコード

        FacebookClient myClient = new FacebookClient(srAcceToken);
        var dicParams = new Dictionary<string, object>();
        dicParams["message"] = "trial message";
        dicParams["caption"] = string.Empty;
        dicParams["description"] = string.Empty;
        dicParams["name"] = "deneme 123";
        dicParams["req_perms"] = "publish_stream";
        dicParams["scope"] = "publish_stream";
        dicParams["access_token"] = srAcceToken;
        var publishResponse = myClient.Post("/" + srPageId + "/feed", dicParams);

画像を投稿したいときに問題が発生します。以下のコードを使用して投稿すると、この画像が表示されます

ここに画像の説明を入力

上記の結果を得るためのコード

            var mediaObject = new FacebookMediaObject
        {
            ContentType = "image/jpeg",
            FileName = "pokemon.jpg"
        }.SetValue(File.ReadAllBytes(Imagepath));

        FacebookClient myClient = new FacebookClient(srAcceToken);
        var dicParams = new Dictionary<string, object>();
        dicParams["message"] = "trial message";
        dicParams["caption"] = string.Empty;
        dicParams["description"] = string.Empty;
        dicParams["name"] = "deneme 123";
        dicParams["req_perms"] = "publish_stream";
        dicParams["scope"] = "publish_stream";
        dicParams["source"] = mediaObject;
        dicParams["type"] = "normal";
        dicParams["access_token"] = srAcceToken;
        var publishResponse = myClient.Post("/" + srPageId + "/photos", dicParams)

しかし、私は以下のように画像を投稿したいのですが、どうすればいいですか?

c# 4.5 - 最新の Facebook SDK を使用していただきありがとうございます

ここに画像の説明を入力

4

1 に答える 1

5

この短いコードがお役に立てば幸いです

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);

===================================

fbParams["access_token"] = account.access_token;

この行は、このページに書き込むためのアクセスを取得します

于 2013-06-20T20:03:26.203 に答える