1

I have a FB app that enable the user to draw shapes and type text on a canvas. The app should have a feature to share what is on canvas on FB as custom story. I was able to do that using PHP SDK.

My question is can I do the same using only JavaScript SDK without any server side code?

Thanks,

Haider

My PHP code is below:

$imgDataBase64 = $_REQUEST["imgBase64"];
$img = str_replace('data:image/png;base64,', '', $imgDataBase64);
$img = str_replace(' ', '+', $img);
$imgData = base64_decode($img);
$pictName = tempnam(sys_get_temp_dir(),"hs").".png";
$ret = file_put_contents($pictName, $imgData);
if ($fbuser) {
try {
    $access_token = $facebook->getAccessToken();
    $imageURI = $facebook->api(
        'me/staging_resources',
        'POST',
        array(
        'file' => "@".$pictName.";type=image/png",
        'access_token' => $access_token
    )
);
$object = $facebook->api(
  'me/objects/testapp:photo',
  'POST',
  array(
    'access_token' => $access_token,
    'object' => array(
        'app_id' => xxxxxxxxxxxxxxx,
        'type' => "testapp:photo",
        'title' => "test",
        'image' => array (
            'url' => $imageURI['uri'],
            'user_generated' => true
        )
    )
  )
);
$action = $facebook->api(
  'me/testapp:share',
  'POST',
  array(
    'photo' => $object['id'],
    'access_token' => $access_token
  )
);
HaiderSahib
  • 380
  • 2
  • 4
  • 16
  • I think `blob` can that do that http://stackoverflow.com/a/21145106/2151050, https://github.com/lukasz-madon/heroesgenerator, http://stackoverflow.com/a/19811684/2151050 – Adam Azad Jun 16 '14 at 19:29
  • Thanks Adam, I was able to get the image link using blob with ajax but when I use FB.api I get ""(#100) Invalid file. Expected file of one of the following types: image/jpg, image/jpeg, image/gif, image/png". The code is :>>> FB.api( 'https://graph.facebook.com/me/staging_resources', 'post', { access_token:authToken, file:blob }, function(response) { console.log("success " + response); } ); – HaiderSahib Jun 16 '14 at 20:46

0 Answers0