問題描述
使用 Facebook 的 PHP SDK,我能夠在我的網站上快速登錄 Facebook.他們只需設置一個可以很容易訪問的 $user
變量.
Using Facebook's PHP SDK, I was able to get Facebook login working pretty quickly on my website. They simply set a $user
variable that can be accessed very easily.
我沒有這么幸運地嘗試讓 Twitter 的 OAuth 登錄工作......坦率地說,他們的 github 材料對于 PHP 和網頁設計相對較新的人來說是令人困惑和無用的,更不用說許多非官方示例了我曾嘗試解決同樣令人困惑或過時的問題.
I've had no such luck trying to get Twitter's OAuth login working... quite frankly, their github material is confusing and useless for someone that's relatively new to PHP and web design, not to mention that many of the unofficial examples I've tried working through are just as confusing or are outdated.
我真的需要一些幫助才能讓 Twitter 登錄工作——我的意思只是一個基本的例子,我點擊登錄按鈕,我授權我的應用程序,它重定向到一個頁面,在那里顯示登錄用戶的姓名.
I really need some help getting Twitter login working--I mean just a basic example where I click the login button, I authorize my app, and it redirects to a page where it displays the name of the logged in user.
非常感謝您的幫助.
編輯我知道存在 abraham 的 twitter oauth 但是它幾乎沒有提供任何讓他的東西工作的說明.
EDIT I'm aware of the existence of abraham's twitter oauth but it provides close to no instructions whatsoever to get his stuff working.
推薦答案
我剛剛從 github 嘗試了 abraham 的 twitteroauth,它似??乎對我來說很好用.這就是我所做的
I just tried abraham's twitteroauth from github and it seems to work fine for me. This is what I did
- git 克隆 https://github.com/abraham/twitteroauth.git莉>
- 將其上傳到您的虛擬主機,例如 www.example.com
- 轉到Twitter 應用 并注冊您的應用程序.您需要的更改是(假設您將使用托管在 http://www.example.com 上的 abraham 的 twitteroauth 示例/twitteroauth)
a) 申請網站將是 http://www.example.com/twitteroauth
b) 應用程序類型將是瀏覽器
c) 回調 url 是 http://www.example.com/twitteroauth/callback.php (Callback.php 包含在git源碼中) - 完成此操作后,您將獲得 CONSUMER_KEY 和 CONSUMER_SECRET,您可以在 twitteroauth 發行版的 config.php 中更新它們.還將回調設置為與 http://www.example.com/twitteroauth/callback 相同.php
- git clone https://github.com/abraham/twitteroauth.git
- Upload this into your webhost with domain, say, www.example.com
- Go to Twitter Apps and register your application. The changes that you need are (assuming that you will use abraham's twitteroauth example hosted at http://www.example.com/twitteroauth)
a) Application Website will be http://www.example.com/twitteroauth
b) Application type will be browser
c) Callback url is http://www.example.com/twitteroauth/callback.php (Callback.php is included in the git source) - Once you do this, you will get the CONSUMER_KEY and CONSUMER_SECRET which you can update in the config.php from the twitteroauth distribution. Also set the callback to be the same as http://www.example.com/twitteroauth/callback.php
就是這樣.如果您現在導航到 http://www.example.com/twitteroauth,您將獲得使用 Twitter 登錄",這會將您帶到 Twitter,授權請求并讓您返回 index.php 頁面.
Thats it. If you now navigate to http://www.example.com/twitteroauth, you will get a "Signin with Twitter", that will take you to Twitter , authorize the request and get you back to the index.php page.
示例將不起作用,但不要擔心.按照以上步驟上傳到服務器.確保從 github 存儲庫重命名文件,即 config-sample.php->config.php
Example will not work but do not worry. Follow the above steps and upload to server. Make sure you rename the file from github repository i.e. config-sample.php->config.php
如果您想查看工作示例,請在此處
if you want to see a working sample, find it here
這篇關于Twitter OAuth (PHP):需要良好的基本示例才能開始的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!