문제 설명
뉴스피드에 댓글 올리기 (Posting a comment on the news feed)
Hey all i am using the following code to post to a posting on my news feed:
<?php
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'fileUpload' => true,
'cookie' => true
));
$user = $facebook‑>getUser();
if ($user) {
try {
$access_token = $facebook‑>getAccessToken();
$user_profile = $facebook‑>api('/me');
$comment = $facebook ‑>api('/xxxxxxxxxxxxxx/comments',
'POST',
array(
'access_token' => $access_token,
'message' => 'testing!'
)
);
} catch (FacebookApiException $e) {
echo ($e);
$user = null;
}
}
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php endif ?>
if ($user) {
$logoutUrl = $facebook‑>getLogoutUrl();
} else {
$statusUrl = $facebook‑>getLoginStatusUrl();
$params = array(
'scope' => 'read_stream, friends_likes, email, read_mailbox, read_requests, user_online_presence, friends_online_presence, manage_notifications, publish_actions, publish_stream, user_likes, user_photos, user_status, user_videos, read_insights'
);
$loginUrl = $facebook‑>getLoginUrl($params);
}
?>
<?php print_r($user_profile); ?>
For some reason i get this error:
OAuthException: (#221) Photo not visible
And i have no idea since i am posting a text comment and not even an image??
If i comment out the code line $comment = $facebook ‑>api('/xxxxxxxxxxxxxx/comments', 'POST', array( 'access_token' => $access_token, 'message' => 'testing!' ) ); it works just fine (as in, displays my info with user_profile). I've tried reading over the page that tells you how to use the comments here and i do ‑ it just doesn't seem to want to work?
What am i missing???
update
using the graph API i was able to do the same thing i am trying to do via PHP so i know it works...:
참조 솔루션
방법 1:
I know it's an old question but...
First, for tests the same enviroment, you have to use your app token, not the Graph API Explorer. Otherwise, you're testing the API with all the permissions.
Second, your problem must be a permission thing (that's why it's working on the API Explorer). You should:
- Ask for publish_permission on the login (not recommended) or,
Ask for publish_permission when the user is ready to send the comment.
- More information about this: Optimizing Permissions Requests
- Here the permissions that you need: Publishing Comments Permissions
As a general rule, when you see a OAuthException, you are having a permission issue.
If the post is photo type, you're going to need a user_photos permission.