Created
April 29, 2014 05:31
-
-
Save oklahomer/11391286 to your computer and use it in GitHub Desktop.
Repros the problem reported at http://stackoverflow.com/questions/23355011/is-it-possible-to-delete-facebook-video-via-graph-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# It repros the problem reported here: http://stackoverflow.com/questions/23355011/is-it-possible-to-delete-facebook-video-via-graph-api | |
use strict; | |
use warnings; | |
use Facebook::OpenGraph; | |
my $fb = Facebook::OpenGraph->new(+{ | |
app_id => 'APP_ID', | |
secret => 'APP_SECRET', | |
}); | |
my $app_token = $fb->get_app_token->{access_token}; | |
$fb->set_access_token($app_token); | |
# To test with 3 different conditions, create 3 app installed users | |
# w/ publish_actions permission. | |
my $test_users = $fb->create_test_users([ | |
+{ | |
permissions => [qw/publish_actions/], | |
locale => 'en_US', | |
installed => 'true', | |
}, | |
+{ | |
permissions => [qw/publish_actions/], | |
locale => 'en_US', | |
installed => 'true', | |
}, | |
+{ | |
permissions => [qw/publish_actions/], | |
locale => 'en_US', | |
installed => 'true', | |
}, | |
]); | |
# POST video and remove it with user token | |
{ | |
my $user = $test_users->[0]; | |
$fb->set_access_token($user->{access_token}); | |
my $res = $fb->publish( | |
'/me/videos', | |
+{ | |
source => 't/resource/IMG_6753.MOV', | |
title => 'testing', | |
description => 'my favorite of all time', | |
} | |
); | |
# { | |
# 'id' => '1391314631152798' | |
# }; | |
$fb->delete($res->{id}); | |
# 100:- GraphMethodException:Unsupported delete request. | |
# DELETE /1391314631152798 HTTP/1.1 | |
# Connection: keep-alive | |
# User-Agent: Facebook::OpenGraph/1.20 | |
# Authorization: OAuth USER_TOKEN_VALUE | |
# Content-Length: 0 | |
# Host: graph.facebook.com | |
# | |
}; | |
# Just to make sure, because app token can be used to publish Open Graph Action, | |
# check if it works for video posting. | |
# POST video with user token and remove it with app token | |
{ | |
my $user = $test_users->[1]; | |
$fb->set_access_token($user->{access_token}); | |
my $res = $fb->publish( | |
'/me/videos', | |
+{ | |
source => 't/resource/IMG_6753.MOV', | |
title => 'testing', | |
description => 'my favorite of all time', | |
} | |
); | |
# { | |
# 'id' => '1384384021847366' | |
# }; | |
$fb->set_access_token($app_token); | |
$fb->delete($res->{id}); | |
# 100:- GraphMethodException:Unsupported delete request. | |
# DELETE /1384384021847366 HTTP/1.1 | |
# Connection: keep-alive | |
# User-Agent: Facebook::OpenGraph/1.20 | |
# Authorization: OAuth APP_ACCESS_TOKEN | |
# Content-Length: 0 | |
# Host: graph.facebook.com | |
# | |
}; | |
# Just to make sure, because app token can be used to publish Open Graph Action, | |
# check if it works for video posting. | |
# POST video and remove it w/ app token | |
{ | |
my $user = $test_users->[2]; | |
$fb->set_access_token($app_token); | |
my $res = $fb->publish( | |
sprintf('/%d/videos', $user->{id}), | |
+{ | |
source => 't/resource/IMG_6753.MOV', | |
title => 'testing', | |
description => 'my favorite of all time', | |
} | |
); | |
# As stated on official document at | |
# https://developers.facebook.com/docs/graph-api/reference/video | |
# valid user access token with publish_actions permission is required | |
# and the following error is returned. | |
# 102:- OAuthException:A user access token is required to request this resource. | |
# POST /100008264770771/videos HTTP/1.1 | |
# Connection: keep-alive | |
# User-Agent: Facebook::OpenGraph/1.20 | |
# Authorization: OAuth APP_ACCESS_TOKEN | |
# Content-Length: 289109 | |
# Content-Type: multipart/form-data; boundary=xYzZY | |
# ........ | |
# --xYzZY | |
# Content-Disposition: form-data; name="title" | |
# | |
# testing | |
# --xYzZY | |
# Content-Disposition: form-data; name="description" | |
# | |
# my favorite of all time | |
# --xYzZY-- | |
}; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment