2012-07-12 232 views
0

我在網絡中發現了這些有用的代碼,但是當我運行代碼並單擊「發佈的牆帖」時,出現此錯誤。API錯誤代碼:191,facebook錯誤

API Error Code: 191 API Error Description: The specified URL is not 
owned by the application Error Message: redirect_uri is not owned by 
the application. 

如何修復此代碼?

感謝

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">  
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>   
    <title>New Graph api & Javascript Base FBConnect Tutorial | Thinkdiff.net</title>  
</head> 
<body>   
    <div id="fb-root"></div>   
    <script type="text/javascript"> 
     window.fbAsyncInit = function() {     
      FB.init({appId: '420291518023354', status: true, cookie: true, xfbml: true}); 

      /* All the events registered */     
      FB.Event.subscribe('auth.login', function(response) {     
       // do something with response      
       login();     
      }); 
      FB.Event.subscribe('auth.logout', function(response) {      
       // do something with response      
       logout();     
      }); 
      FB.getLoginStatus(function(response) {      
       if (response.session) {       
       // logged in and connected user, someone you know       
       login();      
       }     
      });    
     }; 

     (function() {     
      var e = document.createElement('script');     
      e.type = 'text/javascript';     
      e.src = document.location.protocol +      
       '//connect.facebook.net/en_US/all.js';     
      e.async = true;     
      document.getElementById('fb-root').appendChild(e);    
     }()); 

     function login(){     
      FB.api('/me', function(response) {      
       document.getElementById('login').style.display = "block";      
       document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";     
      });    
     } 

     function logout(){     
      document.getElementById('login').style.display = "none";    
     } 

     //stream publish method    
     function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){     
      FB.ui(    
      { 
      method: 'stream.publish',      
      message: '',      
      attachment: {       
       name: name,       
       caption: '',       
       description: (description),       
       href: hrefLink      
      }, 
      action_links: [       
       { text: hrefTitle, href: hrefLink }      
      ], 
      user_prompt_message: userPrompt 
      }, 
      function(response) { 

      }); 
     } 
     function showStream(){ 
      FB.api('/me', function(response) { 
       //console.log(response.id); 
       streamPublish(response.name, 'Thinkdiff.net contains geeky stuff', 'hrefTitle', 'http://localhost:3000/', "Share thinkdiff.net"); 
      }); 
     } 

     function share(){ 
      var share = { 
       method: 'stream.share', 
       u: 'http://thinkdiff.net/' 
      }; 

      FB.ui(share, function(response) { console.log(response); }); 
     } 

     function graphStreamPublish(){ 
      var body = 'Reading New Graph api & Javascript Base FBConnect Tutorial'; 
      FB.api('/me/feed', 'post', { message: body }, function(response) { 
       if (!response || response.error) { 
        alert('Error occured'); 
       } else { 
        alert('Post ID: ' + response.id); 
       } 
      }); 
     } 

     function fqlQuery(){ 
      FB.api('/me', function(response) { 
       var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id); 
       query.wait(function(rows) { 

        document.getElementById('name').innerHTML = 
        'Your name: ' + rows[0].name + "<br />" + 
        '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />"; 
       }); 
      }); 
     } 

     function setStatus(){ 
      status1 = document.getElementById('status').value; 
      FB.api(
       { 
       method: 'status.set', 
       status: status1 
       }, 
       function(response) { 
       if (response == 0){ 
        alert('Your facebook status not updated. Give Status Update Permission.'); 
       } 
       else{ 
        alert('Your facebook status updated'); 
       } 
       } 
      ); 
     } 
    </script> 

    <h3>New Graph api & Javascript Base FBConnect Tutorial | Thinkdiff.net</h3> 
    <p><fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button></p> 

    <p> 
     <a href="#" onclick="showStream(); return false;">Publish Wall Post</a> | 
     <a href="#" onclick="share(); return false;">Share With Your Friends</a> | 
     <a href="#" onclick="graphStreamPublish(); return false;">Publish Stream Using Graph API</a> | 
     <a href="#" onclick="fqlQuery(); return false;">FQL Query Example</a> 
    </p> 

    <textarea id="status" cols="50" rows="5">Write your status here and click 'Status Set Using Legacy Api Call'</textarea> 
    <br /> 
    <a href="#" onclick="setStatus(); return false;">Status Set Using Legacy Api Call</a> 

    <br /><br /><br /> 
    <div id="login" style ="display:none"></div> 
    <div id="name"></div> 

</body> 

回答

0

這是因爲Facebook的權限。當你創建一個新的FB應用程序時,有一個名爲「App Domains」的字段,你只需要從該地址調用FB應用程序,否則它就無法工作。

例如,如果您有應用程序域http://www.mysite.com,並且您試圖從http://mysite.com(不含www)訪問該錯誤附件。

,我建議你在「應用程序域」存儲您的域名的所有可能的組合,包括別名和子域

希望這有助於你