Twitter OAuth(PHP):需要一个很好的基本示例来开始 [英] Twitter OAuth (PHP): Need good, basic example to get started

查看:175
本文介绍了Twitter OAuth(PHP):需要一个很好的基本示例来开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Facebook的PHP SDK,我可以在我的网站上很快获得Facebook登录。他们只是设置了一个 $ user 变量,这个变量很容易被访问。

让Twitter的OAuth登录工作......坦率地说,他们的github资料对于PHP和网页设计相对较新的人来说是令人困惑和无用的,更不用说许多我尝试过的非官方示例同样令人困惑或者



我真的需要一些帮助让Twitter登录工作 - 我的意思只是一个基本的例子,我点击登录按钮,我授权我的应用程序,它重定向到一个显示登录用户名的页面。



我非常感谢您的帮助。



编辑我知道存在亚伯拉罕的twitter oauth ,但它提供了关闭没有任何指示让他的东西工作。

解决方案

我只是三从github编辑亚伯拉罕的twitteroauth,它似​​乎为我工作得很好。这就是我所做的


  1. git clone https://github.com/abraham/twitteroauth.git

  2. 将此上传到您的带有域的网络主机,例如www.example.com
  3. li>
  4. 转至 Twitter应用程序并注册您的应用程序。您需要的更改(假设您将使用在 http://www.example.com上托管的abraham的twitteroauth示例/ twitteroauth

    a)应用程序网站将 http:// www。 example.com/twitteroauth

    b)应用程序类型将为浏览器

    c)回调网址为 http://www.example.com/twitteroauth/callback.php (Callback.php包含在git源文件中)

  5. 完成此操作后,您将获得CONSUMER_KEY和CONSUMER_SECRET,您可以从twitteroauth分发中的config.php中更新CONSUMER_KEY和CONSUMER_SECRET。还要将回调设置为与 http://www.example.com/twitteroauth/callback相同.php

就是这样。如果您现在导航到 http://www.example.com/twitteroauth ,您将获得一个用Twitter登录,这将带你到Twitter,授权请求,并让你回到index.php页面。



编辑:
示例不会工作但不用担心。按照上述步骤并上传到服务器。
确保你从github仓库重命名文件,例如config-sample.php-> config.php



如果你想查看一个工作示例,找到它此处


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.

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.

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.

I really appreciate your help.

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.

解决方案

I just tried abraham's twitteroauth from github and it seems to work fine for me. This is what I did

  1. git clone https://github.com/abraham/twitteroauth.git
  2. Upload this into your webhost with domain, say, www.example.com
  3. 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)
  4. 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

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.

EDIT: 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):需要一个很好的基本示例来开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆