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