开发者

Upload image to fan page problem

.. I'm trying uploade an image to 开发者_StackOverflow社区FB using FaceBookDesktop api for flash .... I'm using Fan page id to upload the picture but that always go to my own album :/

Somebody have some idea ?

Cheers


var values:Object = {message:String(nomFotoASubir), fileName:'FILE_NAME',image: sub};
FacebookDesktop.api('/'+albumID+'/photos', handleUploadComplete, values,'POST');    

Similar to jBit answer, i dont really know if the first '/' is requiered... Anoth. er thing that may cause the error is that you need the page access token and not your user access token. You can obtain this access token easily, see this note and the link...

Page Access Tokens

To perform the following operations as a Page, and not the current user, you must use the Page's access token, not the user access token commonly used for reading Graph API objects. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including application profile Pages) to which the user has administrative access, along with access_tokens for those Pages. Alternatively, you can get a page access token for a single, specific, page by issuing an HTTP GET to /PAGE_ID?fields=access_token with the manage_pages permission, as described above. Publishing to a Page also requires the publish_stream permission, unless otherwise noted.

link to developers page

Please if some of the answers are correct, mark it as correct and if you have other problems lets us know so we could help you to solve the problem and the other people similars problems...


Have you tried posting to an Album (ie using the target album id) instead of the fan page itself?

var params:Object = {image:bitmap, fileName:'FILE_NAME'};
Facebook.api('ALBUM_ID/photos', myCallbackFunction, params, "POST");


By default, uploading an image an image will go to the page of the currently logged in user. You need to get an authentication token for your fan page that authorizes all app users as uploaders to the app. So you will have a token for the user and also for the app. If you us the app token you can upload it.


I had this issue, I wanted to be able to upload a picture to loged user photos and to my app account album.

I mean the picture will always upload in the album that facebook auto create with your app name. in your account and the loged user account once they give permissions to your app.

so knowing this I did the follow.

To manage permisions I use an Array with the permissions needed, I used this

var permissions:Array = new Array("publish_stream", "user_photos" , "publish_actions");
FacebookDesktop.login(onLogin, permissions);

when login is complete then I can upload the image using this

For upload photos to loged user album

// photoBitmap is my image loaded and placed in a Bitmap var
// photoMessage is an string with the message you want to show in the image
// fileName is an string with the name you want to use for the image

    var photoParams:Object = {image: photoBitmap, message: photoMessage, fileName: photoName};

    FacebookDesktop.api("me/photos", uploadCompleteHandle, photoParams, "POST");

    function uploadCompleteHandle(success:Object, fail:Object):void{

        if(success){
           trace("Image uploaded successfuly");
           }else{
             trace("Fail uploading image");
             }
           }

For upload the image to application account album I do use this:

var photoParams:Object = {image: photoBitmap, message: photoMessage, fileName: photoName, access_token: accessToken};

FacebookDesktop.api("/" + albumId + "/photos", uploadCompleteHandle, photoParams, "POST");

private function uploadCompleteHandle(success:Object, fail:Object):void{

    if(success){
       trace("Image uploaded successfuly");
       }else{
         trace("Fail uploading image");
         }
       }

Note that what its change is that I am adding an extra param (access_token) and change ("me/photos") for ("/" + albumId + "/photos") to be able to upload the photos to any photo album in my Facebook account using the Album ID. if you only want to upload to application album you can use ("me/photos"), but I like ("/" + albumId + "/photos") cause I can choose a different album instead of the Facebook auto created album

To find the album ID simple go to your album in Facebook, and at the end of the page you can see someting like this: (https://www.facebook.com/media/set/?set=a.411960374564668.85712.100120829275312&type=3&l=216e24dddf) the album ID is this part 100120829275312

for this code work you need an access_token. to get one you need to go to your application setting in Facebook and add a Open Graph protocol

when creating the Open Graph protocol choose this options for your token

Action type -> Publish

Object -> Article

When you choose the Action type, do click on the right link ("Get Code")

and you will see a window with a lot of code to use for different case. inside those code you can see the value for the access_token, is something like this

AAAGl5aaLlYYBAGqWHMGbxmasf354R15qXf12xAfOBFskr3OZBSEPw7H7rGt9bH4ZCwHS7Eoft9m8q91NYqzY3WOoGHYDnEgybsjONPNSoo8CZB7jdfsfsB

I hope this help you guys Thanks for reading :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜