-1
私はFacebook Canvasアプリを作りたいと思っています。私は自分の許可を得てプロフィールの写真を変更する必要があります。ユーザーのプロフィールを選択したビューポートで取り出し、その原因のオーバーレイだが、&makeprofile=1
が動作していないので、私は映画館モードで写真にリダイレクトされます。私はこのようなものが欲しい。app。PHPを使ってFacebookのプロフィールを変更するには
<?php
session_start();
require_once __DIR__ . '/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'app',
'app_secret' => 'secret',
'default_graph_version' => 'v2.6',
]);
$helper = $fb->getCanvasHelper();
$permissions = ['email','publish_actions']; // optionnal
try {
if (isset($_SESSION['facebook_access_token'])) {
$accessToken = $_SESSION['facebook_access_token'];
} else {
$accessToken = $helper->getAccessToken();
}
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
if (isset($_SESSION['facebook_access_token'])) {
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
} else {
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
// validating the access token
try {
$request = $fb->get('/me');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
if ($e->getCode() == 190) {
unset($_SESSION['facebook_access_token']);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('https://apps.facebook.com/my-first-qode/', $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";
exit;
}
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// getting basic info about user
try {
$requestPicture = $fb->get('/me/picture?redirect=false&width=400&height=400');
$profile_request = $fb->get('/me?fields=name,first_name,last_name,email');
$picture = $requestPicture->getGraphUser();
$profile = $profile_request->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
unset($_SESSION['facebook_access_token']);
echo "<script>window.top.location.href='https://apps.facebook.com/my-first-qode/'</script>";
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// priting basic info about user on the screen
print_r($profile);
echo $profile['name'];
echo "<img src='".$picture['url']."'/>";
//image create
$base_image = imagecreatefrompng("mark.png");
// Get the facebook profile image in 200x200 pixels
$photo = imagecreatefromjpeg($picture['url']);
//$photo = imagecreatefromjpeg("http://graph.facebook.com/".$id."/picture?width=200&height=200");
//resizeImage($photo,920,920);
// read overlay
$overlay = imagecreatefrompng("mark.png");
// keep transparency of base image
imagesavealpha($base_image, true);
imagealphablending($base_image, true);
$lwidth = imagesx($photo);
$lheight = imagesy($photo);
// place photo onto base (reading all of the photo and pasting unto all of the base)
imagecopyresampled($base_image, $photo, 0, 0, 0,0, 200, 200, $lwidth, $lheight);
// place overlay on top of base and photo
imagecopy($base_image, $overlay, 0, 0, 0, 0, 200, 200);
// Save as jpeg
imagejpeg($base_image,'sample3.jpg');
//image create
echo '<img src="sample3.jpg" alt="photo_stamp1" />';
/*$data = [
'message' => 'My awesome photo upload example.',
'source' => $fb->fileToUpload('252676_368007166708864_8124350312635670437_n.jpg'),
// Or you can provide a remote file location
//'source' => $fb->fileToUpload('https://example.com/photo.jpg'),
];
try {
$response = $fb->post('/me/photos', $data);
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
echo 'Photo ID: ' . $graphNode['id'];
*/
// Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
} else {
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('https://apps.facebook.com/my-first-qode/', $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";
}
あなたの答えをありがとう、私はそれをリダイレクトします、選択肢はありません –