开发者

Can I upload photos to a wall belonging to a fan (company) page wall using the Facebook 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜