1

我使用 Facebook 图形 api 使用 codeigniter 从我的网站上传照片到 facebook。 但多次在 facebook 上传相同的图像。 我的代码如下:

# Path to facebook's PHP SDK.       

require_once(APPPATH."libraries/facebook.php");

# Facebook application config.
    // newcheck app [testpurpose ....]

$config = array(
            'appId'      => 'APP ID',
            'secret'     => 'SECRET KEY',
            'fileUpload' => true # Optional and can be set later as well (Using setFileUploadSupport() method).
        );



# Create a new facebook object.
        $facebook = new Facebook($config);

        # Current user ID.
        $user_id = $this->facebook->getUser();

        # Check to see if we have user ID.
        if($user_id) {

            # If we have a user ID, it probably means we have a logged in user.
            # If not, we'll get an exception, which we handle below.
            try {

                # Get the current user access token:
                $access_token = $this->facebook->getAccessToken();

                # Upload photo to the album we've created above:
                $image_absolute_url = 'http://abc.com/research_social_sites/figures/pie.jpg';

                $photo_details = array();
                $photo_details['access_token']  = $access_token;
                $photo_details['url']           = $image_absolute_url;                        # Use this to upload image using an Absolute URL.
                $photo_details['message']       = 'Your picture message/caption goes here'. date('Y-m-d H:i:s') .'->BY RLS';

                $upload_photo = $this->facebook->api('/me/photos', 'POST', $photo_details);

                # Output photo ID:
                echo '<br>Photo ID: ' . $upload_photo['id'];
            } catch(FacebookApiException $e) {
                // If the user is logged out, you can have a 
                // user ID even though the access token is invalid.
                // In this case, we'll get an exception, so we'll
                // just ask the user to login again here.
                $login_url = $this->facebook->getLoginUrl( array('scope' => 'publish_stream, user_photos')); 
                echo 'Error Uploading Image <br> Please <a href="' . $login_url . '">login.</a>';
                }   
        } else {

            # No user, print a link for the user to login and give the required permissions to perform tasks.
            $params = array(
            'scope' => 'publish_stream, user_photos', # These permissions are required in order to upload image to user's profile.
            );

            $login_url = $this->facebook->getLoginUrl($params);
            echo 'You are not Logged in <br> Please <a href="' . $login_url . '">login.</a>';
        }

但它工作正常,但主要问题是它上传的文件不止一次相同的图像。因此,请帮助我提供停止在 facebook 上多次上传图像的解决方案。 感谢您的合作。

4

0 回答 0