ลงทะเบียนด้วย LinkedIn
9 นาที
เข้าสู่ระบบด้วย linkedin สอน บทนำ การเข้าสู่ระบบด้วย linkedin ช่วยให้ผู้ใช้สามารถเข้าสู่ระบบแอปพลิเคชันโดยใช้บัญชี linkedin ของตนได้ ข้อกำหนดเบื้องต้น ในการทำตามบทเรียนนี้ คุณจะต้องมี แอปที่สร้างขึ้นที่ back4app ดูที่ บทเรียนการสร้างแอปใหม่ https //www back4app com/docs/get started/new parse app เพื่อเรียนรู้วิธีการสร้างแอปที่ back4app ตั้งค่า subdomain สำหรับแอป back4app ของคุณ ดูที่ การเปิดใช้งานการโฮสต์เว็บและการค้นหาสด https //www back4app com/docs/platform/activating web hosting เพื่อเรียนรู้วิธีการสร้าง subdomain ใน back4app บัญชี นักพัฒนาของ linkedin https //www linkedin com/developers 1 สร้างแอป back4app ใหม่ ก่อนอื่น คุณต้องมั่นใจว่าคุณมีแอปที่สร้างขึ้นที่ back4app แล้ว อย่างไรก็ตาม หากคุณเป็นผู้ใช้ใหม่ คุณสามารถตรวจสอบ บทแนะนำนี้ https //www back4app com/docs/get started/new parse app เพื่อเรียนรู้วิธีการสร้างแอปหนึ่ง 2 สร้างแอป linkedin ใหม่ เข้าสู่ระบบบัญชี นักพัฒนาของ linkedin https //www linkedin com/developers คลิก \<font color="#2166ae">สร้างแอป\</font> และเลือก \<font color="#2166ae">oauth client id\</font> เลือกชื่อแอปและกรอกข้อมูลที่จำเป็น เช่น \<font color="#2166ae">อีเมลธุรกิจ\</font> และ \<font color="#2166ae">โลโก้แอป\</font> ยอมรับเงื่อนไขและคลิก \<font color="#2166ae">สร้างแอป\</font> ในแอปที่คุณสร้างขึ้นใหม่ ให้คลิก \<font color="#2166ae">ตรวจสอบ\</font> เพื่อยืนยันความเป็นเจ้าของของแอป คุณต้องเป็นเจ้าของหรือผู้ดูแลของหน้า linkedin เพื่อทำการตรวจสอบ ในหน้าการตรวจสอบ ให้คลิก \<font color="#2166ae">สร้าง url\</font> ไปที่ \<font color="#2166ae">url การตรวจสอบ\</font> ที่สร้างขึ้นโดยใช้บัญชีผู้ดูแลหรือเจ้าของของหน้า linkedin ของบริษัท คลิกที่ \<font color="#2166ae">อนุมัติการตรวจสอบ\</font> ตรวจสอบให้แน่ใจว่าแอปของคุณได้รับการตรวจสอบแล้ว ในแอปของคุณ ไปที่แท็บ \<font color="#2166ae">auth\</font> กรอกในฟิลด์ \<font color="#2166ae">redirect urls\</font> และคลิก \<font color="#2166ae">update\</font> 3 ดึงรหัสของคุณ ไปที่ url ต่อไปนี้ โดยเปลี่ยนค่าของ \<font color="#2166ae">client id\</font> , \<font color="#2166ae">redirect url\</font> , และ \<font color="#2166ae">a random string\</font> สำหรับค่าที่คุณสร้างขึ้น สตริงสุ่มนี้ใช้เพื่อหลีกเลี่ยงการโจมตี csrf https //www linkedin com/oauth/v2/authorization?response type=code\&client id=client id\&redirect uri=redirect url\&state=a random string\&scope=r emailaddress เข้าสู่ระบบด้วยบัญชี linkedin ของคุณและเว็บไซต์ที่ถูกเปลี่ยนเส้นทางจะมีรหัสของคุณใน url คัดลอกรหัสส่วนของ url เท่านั้นและรันคำสั่ง curl ต่อไปนี้โดยแทนที่ค่า \<font color="#2166ae">your code\</font> , \<font color="#2166ae">your client id\</font> , \<font color="#2166ae">your client secret\</font> , และ \<font color="#2166ae">your redirect uri\</font> สำหรับค่าของแอปพลิเคชันของคุณ 1 curl x post \\ 2 https //www linkedin com/oauth/v2/accesstoken \\ 3 h 'cache control no cache' \\ 4 h 'content type application/x www form urlencoded' \\ 5 d 'client id=your client id\&client secret=your client secret\&redirect uri=your redirect uri\&code=your code\&grant type=authorization code' เรียกใช้งานและคุณควรจะได้รับโทเค็นการเข้าถึงของคุณ จำไว้ โค้ดนี้สามารถใช้ได้เพียงครั้งเดียว หากคุณได้รับข้อผิดพลาดหรือไม่ใช้โทเค็นของคุณ คุณต้องสร้างโค้ดใหม่เพื่อให้สามารถเรียกใช้งานได้อีกครั้ง 4 เริ่มการพัฒนา ตอนนี้ที่การลงชื่อเข้าใช้ด้วย linkedin ได้ถูกตั้งค่าแล้ว คุณสามารถเริ่มกระบวนการพัฒนาได้แล้ว รูปแบบสำหรับ authdata คือ 1 { 2 "linkedin" { 3 "id" "user's linkedin id (string)", 4 "access token" "an authorized linkedin access token for the user", 5 "is mobile sdk" true|false // set to true if you acquired the token through linkedin mobile sdk 6 } 7 } นี่คือวิธีการสำหรับ ios sdk 1 pfuser loginwithauthtype(inbackground "linkedin", authdata \["access token"\ tokenstring, "id" user, "is mobile sdk" true]) continuewith { task > any? in 2 3 } และนี่คือสำหรับ android sdk 1 map\<string, string, bool> authdata = new hashmap\<string, string, bool>(); 2 authdata put("access token", tokenstring); 3 authdata put("id", user); 4 authdata put("is mobile sdk", true); 5 task\<parseuser> t = parseuser loginwithinbackground("google", authdata); 6 t continuewith(new continuation\<parseuser, void>() { 7 public void then(task task) throws exception { 8 if (task iscancelled()) { 9 log w(tag, "task cancelled"); 10 } else if (task isfaulted()) { 11 log w(tag, "save fail" + task geterror()); 12 utilities showtoast(getresources() getstring(r string errorlogin) + task geterror(), mainactivity this); 13 } else { 14 // the object was saved successfully 15 parseuser user = (parseuser)task getresult(); 16 log w(tag, "success " + user getobjectid() + " " + user getusername() + " " + user getemail() + " " + user getsessiontoken()); 17 } 18 } 19 }