OAuthException when trying to upload/post photos t

2019-07-02 01:20发布

I am currently trying to upload photos to pages and groups through an app. I have these codes:

try
{
    $facebook->setFileUploadSupport(true);
    $args = array('message' => 'This is my image caption',); 
    $args['image'] = '@'.realpath('./uploads/terragarden1.png');
    $response = $facebook->api('/GROUP_ID/photos/','POST',$args);
}
catch(FacebookApiException $e)
{
     echo "Error: ".$e; 
}

The value of $args['image'] would be something like this:

@/home/publica/public_html/AutoPost/uploads/terragarden1.png

The problem is that it throws an OAuthException: An unknown error has occurred. I don't quite know what to do with this kind of error.

Additional:
When I try to post image using the same code and just changing
$response = $facebook->api('/GROUP_ID/photos/','POST',$args);

into $response = $facebook->api('/me/photos/','POST',$args);, the image would successfully be posted on the user's wall. What might be the problem here?

2条回答
We Are One
2楼-- · 2019-07-02 02:10

This works fine for me on pages:

$attachements = array(                                  
        'access_token' => $page->getToken(),
        'message' => $post_pub['title'],
        'url' => 'http://site.com/images/your_image.png' );                             
        try{
           $result = $facebook->api('/'.$page->getIdFacebook().'/photos', 'POST', $attachements, function(){
           }); 
        }
        catch(Exception $e){ }

Might want to try switching from 'image' to 'url'

查看更多
小情绪 Triste *
3楼-- · 2019-07-02 02:12

I got the same issue.

There is a topic about it here: https://developers.facebook.com/bugs/1430985030446221?browse=external_tasks_search_results_527428908614f7c36099745

I've been tried to do this with js sdk, with the same error response.

查看更多
登录 后发表回答