Twitter OAuth (PHP):需要良好的基本示例才能开始 [英] Twitter OAuth (PHP): Need good, basic example to get started

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

问题描述

使用 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

  1. git 克隆 https://github.com/abraham/twitteroauth.git
  2. 将其上传到您的虚拟主机,例如 www.example.com
  3. 转到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源码中)
  4. 完成此操作后,您将获得 CONSUMER_KEY 和 CONSUMER_SECRET,您可以在 twitteroauth 发行版的 config.php 中更新它们.还将回调设置为与 http://www.example.com/twitteroauth/callback 相同.php
  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

就是这样.如果您现在导航到 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):需要良好的基本示例才能开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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