2011-06-29 8 views
0

stream_publishコールでFacebookのエラーが発生しました。私は実際にFconnect用のMagentoの拡張機能を使用しました。 Fconnect & Floginは正常に動作しています。しかし、ユーザーが注文するときは、ユーザーの壁に掲示する必要があります。そのために私はFacebookのクライアントファイルgenerateSignature方法でこのfacebookの不正な署名stream_publish call

document.observe('click', function(e){ 

    if (e.element().match('a[rel^=facebook-connect]') || e.element().match('button[rel^=facebook-connect]')) { 

     e.stop(); 

     FB.login(function(response){ 



      if(response.status=='connected') setLocation('http://staging.mystore.com/facebook/customer_account/connect/'); 



     }, {perms:"email,publish_stream"}); 

    } 

}); 

のように実装されているAPIを呼び出して、この

private function _generateSig($params_array) 
{ 
    Mage::log($params_array); 
    $str = ''; 
    ksort($params_array); 
    foreach ($params_array as $k=>$v) { 
     $str .= "$k=$v"; 
    } 

    $str .= $this->_secret; 
    Mage::log($str); 
    Mage::log('md5 sigs:: ' . md5($str)); 

    return md5($str); 
} 

&私のコードは、ログインした後に、この

$message = 'just placed an order on mystore.com'; 

    $attachment = array(
    'name' => "mystore", 
    'href' => 'http://www.mystore.com/', 
    'description' => 'New order on mystore.com', 
    'media' => array(array('type' => 'image', 
    'src' => 'http://www.mystore.com/skin/frontend/default/mystore/images/logo.png', 
    'href' => 'http://www.mystore.com/'))); 

    $action_links = array(array('text' => '[email protected]', 'href' => 'http://www.mystore.com/')); 

    $attachment = json_encode($attachment); 
    $action_links = json_encode($action_links); 

    try{ 
     // if($facebook->api_client->stream_publish($message, $attachment, $action_links, null, $target_id)) 
     if($this->_getClient()->call('facebook.stream.publish', 
           array($message, $attachment, $action_links, 
             $this->_getClient()->users->getLoggedInUser(), 
             Mage::getSingleton('facebook/config')->getApiKey()) 
           ) ) 
     { 
      Mage::log("Added on FB Wall"); 
     } 

     } catch(Exception $e) 
     { 
      Mage::log("Exception in wall write"); 

      Mage::log($e); 
     } 

のようなものであるようですログで見つけた署名は

api_key=XXXXXXXXmethod=facebook.stream.publishsession_key=2.AQCm5fABfobInAS5.3600.1309352400.1-1000025660978090=just placed an order on mystore.comcall_id=1309345883.3068format=JSONv=1.01={"name":"mystore","href":"http:\/\/www.mystore.com\/","description":"New order on mystore.com","media":[{"type":"image","src":"http:\/\/www.mystore.com\/skin\/frontend\/default\/mystore\/images\/logo.png","href":"http:\/\/www.mystore.com\/"}]}2=[{"text":"[email protected]","href":"http:\/\/www.mystore.com\/"}]3=1000025660978094=5070afefb42b162aff748f55ecf44d110d9e2a90117ee1704e2adb41f1d190fa 
です

私はFacebookでの開発を一度も行っていないので、アイデアは何もありません。解決策を教えてください。 &私はあなたがこれを理解するために他の情報を必要とするかどうか教えてください。

そうそうもう一つAPIを呼び出すためにその本

private function _prepareParams($method, $params) 
{ 

    $defaultParams = array(
     'api_key' => $this->_apiKey, 
     'call_id' => microtime(true), 
     'format' => 'JSON', 
     'v'  => '1.0' 
    ); 

    if($this->_sessionKey){ 
     $defaultParams['session_key'] = $this->_sessionKey; 
    } 

    $params = array_merge($defaultParams, $params); 
    foreach ($params as $key => &$val) { 
     if (!is_array($val)) continue; 
     $val = Zend_Json::encode($val); 
    } 

    $params['method'] = $method; 

    if(isset($params['sig'])) { 
     unset($params['sig']); 
    } 
    $params['sig'] = $this->_generateSig($params); 

    return $params; 
} 


public function call($method, $args=array()) 
{ 
    Mage::log($args); 
    $params = $this->_prepareParams($method, $args); 

    $client = self::_getHttpClient() 
      ->setUri(self::FACEBOOK_REST_URI) 
      ->setMethod(Zend_Http_Client::POST) 
      ->resetParameters() 
      ->setParameterPost($params);  

    try { 
     $response = $client->request(); 
    } catch(Exception $e) { 
     throw new Mage_Core_Exception('Service unavaliable'); 
    } 

    if(!$response->isSuccessful()) { 
     throw new Mage_Core_Exception('Service unavaliable'); 
    } 

    $result = Zend_Json::decode($response->getBody()); 

    //json decode returns float on long uid number? is_json check? old php? 
    if(is_float($result)){ 
     $result = $response->getBody(); 
    } 

    if(is_array($result) && isset($result['error_code'])) { 
     throw new Mage_Core_Exception($result['error_msg'], $result['error_code']); 
    } 

    return $result; 
} 

のように(callメソッド)APIを呼び出しているクライアントファイルのコード私はそれらのどれもが

に機能していない二つの方法 $this->_getClient()->call('facebook.stream.publish', & $this->_getClient()->call('stream_publish', を使用

答えて

0

ok私は間違いを見つけます

私のコードを見て

uは 形式= JSONvを見ることができる
format=JSONv=1.01={"name":"mystore","href":"http:\/\/www.mystore.com\/","description":"New order on mystore.com","media":[{"type":"image","src":"http:\/\/www.mystore.com\/skin\/frontend\/default\/mystore\/images\/logo.png","href":"http:\/\/www.mystore.com\/"}]}2=[{"text":"[email protected]","href":"http:\/\/www.mystore.com\/"}]3=1000025660978094=5070afefb42b162aff748f55ecf44d110d9e2a90117ee1704e2adb41f1d190fa 

= 1.01 = {...} 2 = [{...}]問題Iは、パラメータの数値配列を使用しました。彼らは私が連想配列の問題を修正したら、ここで正しく 作業私のコードの開始を、パラメータについてのuの詳細をあげるのリンクである配列 のようなメッセージ= {新しい秩序}添付ファイル= {....} 関連付けられている必要がありますストリームに渡す。公開する http://schoolout.net/en/developers/view/39

これは他の誰かにも役立ちます。

関連する問題