2014-01-31 3 views
-1

내가 만든 facebook 사이트에 cron을 통한 자동 게시를 구현하려고합니다. 이에 대한 어려운 부분은 프로세스 중에 로그인 한 계정이없는 것입니다. 내가 게시물을 할 때 누군가가 내 코드 QQ 도움말페이스 북 페이스 북 사이트 (Curl)에 자동 게시

$username = "xx"; 
$password = "xx"; 

// access to facebook home page (to get the cookies) 
$curl = curl_init(); 
curl_setopt ($curl, CURLOPT_URL, "http://www.facebook.com"); 
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($curl, CURLOPT_ENCODING, ""); 
curl_setopt ($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_facebook.cookie'); 
curl_setopt ($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); 
$curlData = curl_exec ($curl); 


// do get some parameters for login to facebook 
$charsetTest = substr ($curlData, strpos ($curlData, "name=\"charset_test\"")); 
$charsetTest = substr ($charsetTest, strpos ($charsetTest, "value=") + 7); 
$charsetTest = substr ($charsetTest, 0, strpos ($charsetTest, "\"")); 

$locale = substr ($curlData, strpos ($curlData, "name=\"locale\"")); 
$locale = substr ($locale, strpos ($locale, "value=") + 7); 
$locale = substr ($locale, 0, strpos ($locale, "\"")); 

$lsd = substr ($curlData, strpos ($curlData, "name=\"locale\"")); 
$lsd = substr ($lsd, strpos ($lsd, "value=") + 7); 
$lsd = substr ($lsd, 0, strpos ($lsd, "\"")); 

// do login to facebook 
curl_setopt ($curl, CURLOPT_URL, "https://login.facebook.com/login.php?login_attempt=1"); 
curl_setopt ($curl, CURLOPT_POST, 1); 
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt ($curl, CURLOPT_POSTFIELDS, 
    "charset_test=" . $charsetTest . 
    "&locale=" . $locale . 
    "&non_com_login=&email=" . $username . 
    "&pass=" . $password . 
    "&charset_test=" . $charsetTest . 
    "&lsd=" . $lsd); 
curl_setopt ($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_facebook.cookie'); 
$curlData = curl_exec ($curl);//this actually is the code of my facebook profile page so it works 


//Page access_token 
$access_token = "xx"; 
$params=array(
     'access_token'=>$access_token, 
     'message'=> "Testing newwjjj7wwwg", 
     'name'=>'TEST6678888'); 

//Postng to facebook page 
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); 
curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/".variable_get('webconnect_facebook_pageId')."/feed"); 
$result = curl_exec($curl); 

curl_close ($curl); 

에서 문제를 볼 수 있습니까 ...

나는 내 문제에 대한 많은 사이트를 확인하고 어떻게 든 그것은 여전히 ​​작동하지 않습니다 { "error": { "message": "Error validating access token: This may be because the user logged out or may be due to a system error.", "type": "OAuthException", "code": 190, "error_subcode": 467 } }

나는 사용자 access_token은 사용하려고 : { "error": { "message": "(#200) The user hasn't authorized the application to perform this action", "type": "OAuthException", "code": 200 } }

는 것은 내가 ... 어떤 아이디어 권한을 부여 않았다된다?

+0

사용자를 얼마나 정확하게인가 했습니까? 일반 사용자 액세스 토큰은 트릭을 수행하지 않습니다. 확장 된 권한'publish_stream'이 필요합니다. https://developers.facebook.com/docs/reference/login/extended-permissions/ – thpl

답변

0

사용자가 Facebook에 로그인되어 있고 액세스 토큰이 유효한 동안 브라우저 세션에서 코드를 게시 할 수 있습니까? 새 테스트 사용자를 만들어 액세스 토큰이 유효하고 올바른 권한이 부여되는지 확인할 수 있습니다. 해당 시나리오에서 앱이 작동하는 경우 사용자를 로그인 상태로두고 원래 테스트 케이스 (첫 번째 테스트의 액세스 토큰 사용)로 시도하십시오. 원래 코드에 문제가 있는지 또는 세션/데이터 (액세스 코드, 사용 권한) 문제인지 여부를 알려줍니다.

0

나는 게시물을하려고 할 때 : { "오류": { "메시지": "오류가 액세스 토큰의 유효성을 검사 :. 사용자가 로그 아웃 또는 인해 시스템 오류 일 수 있습니다 때문일 수 있습니다" , "유형": "OAuthException", "코드": 190, "error_subcode": 467}} 토큰의 수명이 만료있어 때문이다

. 토큰의 수명을 연장해야합니다. here을 참조하십시오.

나는 사용자 access_token은 사용하려고하면 : { "오류": { "메시지": "사용자가이 작업을 수행 할 수있는 응용 프로그램을 승인하지 않은 (# 200)" 를, "유형" "OAuthException", "code": 200}}

이렇게하려면 status_update 근처의 체크 박스를 선택해야합니다. here.