我正在尝试从我的 Facebook 应用程序中以用户身份发布图像。目前,此功能仍在开发中,当我尝试使用WAMP server
on测试它时localhost
,类中的一个cURL
函数Facebook API SDK
会引发异常错误:
{"error_code":60,"error":{"message":"SSL 证书问题,验证 CA 证书是否正常。详细信息:\nerror:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed","type": "CurlException"}}null0.90752005577087 145684992172054|e259ec293812a5276a61d3181c395077
我已经检查过,并且php.ini
在Apache
和PHP
目录中都有正确的设置。
我试图在Easy PHP
withPHP 5.4
和 on WAMP
with上运行这个PHP 5.3
。(启用 cURL 扩展)。
我已经open SSL
安装在两个本地服务器上。
我知道您可以通过更改配置来解决这个问题CURL_opt
,但是修改 Facebook 基类并危及我的应用程序的安全性(中间人攻击)对我来说确实是最后的手段。
提前感谢您的帮助!
我的代码:
test.php:
<?php
session_start();
require 'FB_auth.php';
require 'includes.php';
require 'functions_fb.php';
$start = (float) array_sum(explode(' ',microtime()));
//echo json_encode(photoToFacebook(299, 402, 134));
// echo json_encode(photoToFacebook(724, 402, 165));
// postToFacebook($db, 402, 134);
$end = (float) array_sum(explode(' ',microtime()));
$duration = ($end-$start);
echo $duration;
echo "<br/>" . $facebook->getAccessToken();
?>
functions_fb.php
<?php
function photoToFacebook($hr_id, $user_id, $job_id){
global $db, $FEED_PATH, $JOB_IMAGES_FOLDER , $facebook;
$path = $_SERVER['DOCUMENT_ROOT'] . "/";
$JOB_IMAGES_FOLDER = "images/job_images/";
$company = $db->getCompany($hr_id);
// perapre the job photo.
$photo = $db->getJobPhoto($job_id);
if (empty($photo)){
$photo = $db->getLogo($hr_id);
}
else{
$photo = $JOB_IMAGES_FOLDER . $photo;
}
try{
// At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);
// Get album id if exists.
$album_uid = $db->getAlbumId($user_id);
$fb_user_id = $db->getFBUserId($user_id);
if (empty($album_uid)){
// Create an album
$album_details = array(
'message'=> 'Check out my company\'s job opportunities',
'name'=> "Job opportunities at {$company}"
);
$create_album = $facebook->api("/{$fb_user_id}/albums", 'post', $album_details);
echo json_encode($create_album);
$album_uid = $create_album["id"];
$db->saveAlbumId($user_id, $create_album["id"]);
}
$job_title = $db->getJobTitle($job_id);
$link = Bitly::make_bitly_url($FEED_PATH . "show_job.php?jid={$job_id}&th_uid={$user_id}&tp=1&pc=1", BITLY_APP_USERNAME,BITLY_APP_KEY,'json');
$photo_details = array(
'message'=> $job_title . "!\n" . $company . " is looking for you.\nOpen the link for details and apply.\n" . $link
);
$path .= $photo;
$photo_details['image'] = '@' . $path; //realpath($file);
// echo $album_uid;
$upload_photo = $facebook->api("{$fb_user_id}/photos", 'post', $photo_details);
// $db->updateAutoPostActivity($user_id, $job_id,1, json_encode($upload_photo));
// $db->updateAutoPostJob($job_id, $user_id);
return $upload_photo;
}
catch (FacebookApiException $e) {
echo "error:" . json_encode($e->getResult());
// $db->updateAutoPostActivity($user_id, $job_id,1, json_encode($e->getResult()));
// AtavMail::SendRichedMail(null , "", "Error on auto process - posting photo to FB", "Where - Job Id: {$job_id} , User Id: {$user_id}", json_encode($e->getResult()));
}
}
?>