开发者

Can I upload photos to a wall belonging to a fan (company) page wall using the Facebook Graph API?

开发者 https://www.devze.com 2022-12-29 15:12 出处:网络
I need to know if it\'s possible to make it so authorized users can upload photos to a fan page of a comp开发者_开发技巧any (to the wall) using the graph API.

I need to know if it's possible to make it so authorized users can upload photos to a fan page of a comp开发者_开发技巧any (to the wall) using the graph API. Also, is it possible to become like (become a fan) of a company page through the api once the user is authorized.


Yes you can. You need to obtain your admin access token by using the Graph API explorer (https://developers.facebook.com/tools/explorer) and with a call to

https://graph.facebook.com/{adminfacebookid}/accounts

this will list all pages and apps your admin has access to. Look for the fan page in question and copy the accessToken.

Next get the albumid by clicking on the id of the page, then adding /albums to the request

armed with this you can then post the image data to the url, using the facebook web client

like this

protected void PublishToPublicGallery(string accessToken, string filename, long albumId, string imagename)
        {

            var facebookClient = new FacebookClient(accessToken);
            var mediaObject = new FacebookMediaObject
            {
                FileName = filename,
                ContentType = "image/jpeg"
            };
            var fileBytes = System.IO.File.ReadAllBytes(filename);
            mediaObject.SetValue(fileBytes);

            IDictionary<string, object> upload = new Dictionary<string, object>();
            upload.Add("name", imagename);
            upload.Add("source", mediaObject);
            var result = facebookClient.Post("/" + albumId + "/photos", upload) as JsonObject;    
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消