2012-09-28 35 views
1

我使用下面的代碼的FB註冊插件:Facebook上註冊登錄到FB長/許多自定義字段後插件返回「無效的client_id」

<html xmlns:fb="http://ogp.me/ns/fb#"> 

    <script type="text/javascript"> 
    window.fbAsyncInit = function() { FB.init({appId: 'xxx', status: true, cookie: true, xfbml: true}); }; 
    (function() { 
     var e = document.createElement('script'); 
     e.async = true; 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
     document.getElementById('fb-root').appendChild(e); 
    })(); 
</script> 

這裏是我想要的字段列表:

      <?php /* There seems to be a character limit for fields causing "invalid client_id" on log in/out */?> 
         <fb:registration redirect-uri="https://xxx.secure.xxx.com/register/fb_submit.php" 
          fields='[ 
          {"name":"name","view":"prefilled"}, 
          {"name":"email"}, 
          {"name":"password"}, 
          {"name":"s_question","description":"Secret Question","type":"select","options":{"2":"In which city were you born?","4":"What is your favorite book?","3":"What is your favorite pets name?","6":"What is your favorite vacation spot?","1":"What is your mothers maiden name?"}}, 
          {"name":"s_answer","type":"text","description":"Secret Answer"}, 
          {"name":"first_name"}, 
          {"name":"last_name"}, 
          {"name":"address_co","description":"Care of (Optional)","type":"text","no_submit":true}, 
          {"name":"address","description":"Mailing Address","type":"text"}, 
          {"name":"address2","description":"Apartment/Unit","type":"text","no_submit":true}, 
          {"name":"street_address","description":"Street Address (if using a P.O. box above)","type":"text","no_submit":true}, 
          {"name":"location","view":"prefilled"}, 
          {"name":"city","view":"not_prefilled","description":"City","type":"text"}, 
          {"name":"state","view":"not_prefilled", "description":"State","type":"select","options":{"AA":"AA - Armed Forces Americas","AE":"AE - Armed Forces","AK":"AK - Alaska","AL":"AL - Alabama","AP":"AP - Armed Forces Pacific","AR":"AR - Arkansas","AS":"AS - American Samoa","AZ":"AZ - Arizona","CA":"CA - California","CO":"CO - Colorado","CT":"CT - Connecticut","DC":"DC - District of Columbia","DE":"DE - Delaware","FL":"FL - Florida","FM":"FM - Federated States of Micronesia","GA":"GA - Georgia","GU":"GU - Guam","HI":"HI - Hawaii","IA":"IA - Iowa","ID":"ID - Idaho","IL":"IL - Illinois","IN":"IN - Indiana","KS":"KS - Kansas","KY":"KY - Kentucky","LA":"LA - Louisiana","MA":"MA - Massachusetts","MD":"MD - Maryland","ME":"ME - Maine","MH":"MH - Marshall Islands","MI":"MI - Michigan","MN":"MN - Minnesota","MO":"MO - Missouri","MP":"MP - Northern Mariana Islands","MS":"MS - Mississippi","MT":"MT - Montana","NC":"NC - North Carolina","ND":"ND - North Dakota","NE":"NE - Nebraska","NH":"NH - New Hampshire","NJ":"NJ - New Jersey","NM":"NM - New Mexico","NV":"NV - Nevada","NY":"NY - New York","OH":"OH - Ohio","OK":"OK - Oklahoma","OR":"OR - Oregon","PA":"PA - Pennsylvania","PR":"PR - Puerto Rico","PW":"PW - Palau","RI":"RI - Rhode Island","SC":"SC - South Carolina","SD":"SD - South Dakota","TN":"TN - Tennessee","TX":"TX - Texas","UT":"UT - Utah","VA":"VA - Virginia","VI":"VI - Virgin Islands","VT":"VT - Vermont","WA":"WA - Washington","WI":"WI - Wisconsin","WV":"WV - West Virginia","WY":"WY - Wyoming"}}, 
          {"name":"zip","description":"5-digit Zip Code","type":"text"}, 
          {"name":"phone","description":"Phone (800-555-1212)","type":"text"}, 
          {"name":"referred_by","description":"Referred by-Email or site nickname (Optional)","type":"text","no_submit":true}, 
          {"name":"cert_code","description":"Gift Certificate Code (Optional)","type":"text","no_submit":true}, 
          {"name":"sel_hear_about","description":"How Did You Hear About Us?","type":"select","options":{"1":"Friend","2":"Newspaper","3":"Magazine","4":"Internet Search","5":"Internet Ad","6":"Website","8":"site2","9":"site3","10":"Other","11":"TV","12":"Radio"}}, 
          {"name":"hear_about","description":"newspaper/blog/website/friend name? (Optional) ","type":"text","no_submit":true}, 
          {"name":"birthday"}, 
          {"name":"hours","description":"Hours Spent Reading per Week (Optional)","type":"select","options":{"0":"0","1-5":"1-5","6-10":"6-10","11-20":"11-20","21-30":"21-30","31-40":"31-40","41+":"41+"},"no_submit":true} 
          ]' onvalidate="validate"> 
         </fb:registration> 

這裏是我的validate()函數:

 function validate(form) 
    { 
     errors = {}; 
     var dt = new Date(), expiryTime = dt.setTime(dt.getTime() + 1000*5); 
     var expires = dt.toGMTString(); 

     if (form.first_name == "") 
     { 
      errors.first_name = "Please choose a First Name"; 
     } 

     if (form.s_question == "-1") 
     { 
      errors.s_question = "Please choose a Secret Question"; 
     } 
     if (form.s_answer == "") 
     { 
      errors.s_answer = "Please type an answer to your Secret Question"; 
     } 
     if (form.address_co !== "") 
     { 
      set_cookie('address_co', form.address_co, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (form.address == "") 
     { 
      errors.address = "Please type your mailing address"; 
     } 
     if (form.address2 !== "") 
     { 
      set_cookie('address2', form.address2, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (form.street_address !== "") 
     { 
      set_cookie('street_address', form.street_address, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (form.zip == "") 
     { 
      errors.zip = "Please type a 5-digit Zip Code" 
     } 
     else if (form.zip.length != 5) 
     { 
      errors.zip = "Zip Code must be 5 digits"; 
     } 
     else if (isNaN(form.zip)) 
     { 
      errors.zip = "Zip Code must be a number"; 
     } 


     if (form.phone == "") 
     { 
      errors.phone = "Please type your phone number"; 
     } 
     if (form.referred_by !== "") 
     { 
      set_cookie('referred_by', form.referred_by, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (form.cert_code !== "") 
     { 
      set_cookie('cert_code', form.cert_code, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (!form.sel_hear_about) 
     { 
      errors.sel_hear_about = "Please choose how you heard about us"; 
     } 
     if (form.hear_about !== "") 
     { 
      set_cookie('hear_about', form.hear_about, expires, '/register', 'secure.xxx.com', true); 
     } 
     if (form.hours !== "-1") 
     { 
      set_cookie('hours', form.hours, expires, '/register', 'secure.xxx.com', true); 
     } 

     return errors; 
    } 

如果用戶已經當訪問這個註冊表格時登錄到FB,FB字段被填充並且表單工作。 但是,如果用戶未登錄FB並在表單上選擇FB提示「使用您的個人資料信息登錄以預填下面的表單」,然後向FB提供登錄憑證,表單將消失並由來自FB的相當通用的'client_id'錯誤。

如果用戶然後刷新頁面,他/她已經登錄到FB並且填充正確的FB字段。

我驗證了JSON字段列表。在測試過程中,我發現如果我將字段列表縮小爲:

       fields='[ 
          {"name":"name","view":"prefilled"}, 
          {"name":"email"}, 
          {"name":"password"}, 
          {"name":"s_question","description":"Secret Question","type":"select","options":{"2":"In which city were you born?","4":"What is your favorite book?","3":"What is your favorite pets name?","6":"What is your favorite vacation spot?","1":"What is your mothers maiden name?"}}, 
          {"name":"s_answer","type":"text","description":"Secret Answer"}, 
          {"name":"first_name"}, 
          {"name":"last_name"},                ]' onvalidate="validate"> 

然後我沒有收到錯誤。如果我將最長的字段(上面的狀態字段)添加回來,client_id錯誤將返回。我可以添加其他較短字段的組合並獲得相同的錯誤,而不是添加狀態。這讓我認爲我正在爲JSON字段列表創造某種最大大小限制。可能不是用於發送給FB的實際JSON,而是在登錄後FB發回的相應隱藏字段中。

如果我無法解決此問題,我打算只獲取基本FB字段並將其餘到另一個頁面。自從表格和我的支持註冊表以來,我更願意將它放在一個整體中。在FB數據加載到表單中後(刷新時),所有工作都會進行代碼編寫。

感謝您耐心等待這段冗長的描述。

回答

0

我沒有這方面的任何修復,我只能提供一個可能的(不,其實我覺得最有可能的)的解釋:

<fb:registration>標籤做什麼,像所有其他插件,基本上是在頁面中創建一個iframe,將查詢字符串中傳遞的所有參數作爲GET參數獲取。

因此,您爲註冊表單定義的很多字段意味着iframe的URL中的長查詢字符串。

的問題是,瀏覽器限制的URL的可能長度 - 見https://stackoverflow.com/a/417184/1427878http://www.boutell.com/newfaq/misc/urllength.html

和Web服務器做得一樣好,他們說之前,「嗯,這是一個有點多,我通過獲取進程,很抱歉,但沒有對不起......」

所以,當你的報名表可能有很多,當用戶已經登錄定義的字段的工作,因爲iframe網址的長度保持在您的瀏覽器強制執行的限制或Facebook的服務器 - 如果用戶是而不是登錄並單擊登錄按鈕,它們通過Facebook Auth流程重定向,成功登錄後它們應該「發送回」的URL(此例中爲帶有所有GET參數的註冊表單的地址)被傳輸作爲Auth對話框URL中的GET參數,以及其他參數。 (以及發送URL時作爲另一個URL內的GET參數吹起來更加施加必要的URL編碼...)

而這在很長 URL的結果,這是不能被傳輸/處理的任何更多的是由瀏覽器或Facebook服務器實施的限制。 (由於Facebook收到錯誤信息,因此很可能Facebook服務器拒絕在這種情況下處理它。)

因此,您可以嘗試使用Facebook打開一個錯誤報告 - 它們將設置最大限制GET URL長度可以修復此問題;但如果他們願意願意這樣做,可能是另一個問題。 (因爲允許更長的請求URL也可能有其他含義。)

即使他們這樣做了,您仍然可能會碰到用戶正在使用的瀏覽器的路障 - 如果Internet Explorer中的當前限制仍爲2,048個字符一個URL的路徑部分,這可能是下一部分,其中許多字段的註冊表將在前端中斷...

+0

謝謝,CBroe,詳細的解釋。我不會向Facebook進行無法做出的更改,我會重新編碼以僅獲取Facebook表單上的基本字段,並在本地獲取其他信息。我感謝你的意見。 –