Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 用新浪微博账号登录(第三方登录)

用新浪微博账号登录(第三方登录)

Jun 23, 2016 pm 02:22 PM

我下载了新浪SDK包,我测试的时候,输入我的微博账号和密码,点击授权连接按钮后,出现Sorry, that page doesn’t exist!这个页面,请问大家应该怎么解决?谢谢大家……


回复讨论(解决方案)

PHP下通过API实现与新浪微博同步

今天下午弄了个新浪微博同步应用,测试好多次,终于成功了,下面说一下我的配置过程。欢迎大家来我的新浪微博做客!

首先, 得有sina微博的帐号,没有就注册一个,然后做个开发者,可以从微博中点过去,也可以直接输入网 址:http://open.t.sina.com.cn,选择我是开发者,在选择创建应用,进去填写开发者信息,成功之后获得你的APP KEY 和 APP SECRET,把它们复制下来,保存好了。

然后,去下载SDK文档,选择PHP语言的,看到“通过OAuth验证方式 ”,我用的就是这个,点下面的链接download下来,解压到本地。

第三步,开始测试了。把解压后的文件中的weobodemo文件夹拷贝到测试的目录下面,也就是你的站点目录,提前要得配置好虚拟域名,不会的可以参考我的另一篇文章,用apache配置独立虚拟域名。

weibodemo这个文件夹下面有个配置文件config.php,打开之后该做什么,你也就知道了,把你的APP KEY 和 APP SECRET 写进去。在浏览器中打开这一层目录,自动运行index.php文件,就不?嗦了。

到这你会发现,出错了:Notice: Undefined index: SCRIPT_URI in D:\www\weibodemo\index.php on line 13

打开index.php,发现$_SERVER['SCRIPT_URI'],$_SERVER的参数根本就没有这个SCRIPT_URI,先别管,点击下面的链接,接着又出错:Sorry, that page doesn’t exist!

到这,估计好多人要放弃了,一下子不知道该怎么办了。其实,别把新浪微博这写应用开发想的那么高深,一般人是能够看明白的。仔细瞅瞅index.php吧,刚才点击的链接地址是WeiboOAuth这个类里面的getAuthorizeURL这个方法生成的,而且和接下来的callback函数有关,也就是callback.php文件。

从这,我们不难想到这个过程:先获取本地配置文件config.php中的APP KEY 和APP SECRET,接着肯定是要验证这个APP KEY 是否合法,另外询问我们是否授权给这个应用来同步更新微博,如果条件成立,那么就通过callback.php返回到本地上来,我们就可以在这个回调页面上写微博,最后点击发表,从t.sina.com.cn新浪官方微博上登录进去就可以看见刚才所发的文章消息了,下面应该注明“来自xxx”

了 解这个原理就不难了,把$_SERVER['SCRIPT_URI']改为我们本地的地址,也就是所在目录虚拟域名的地址,以便于返回到 callback.php上来,这样就不会出现找不到页面的错误了。比如:我的本地虚拟郁闷是http://localhost.com,知道d: /www/这个文件夹,我的weibodemo文件夹就放在/www/下面,那么我就把$_SERVER['SCRIPT_URI']改为http://localhost.com/weibodemo,连上后面的/callback.php就OK了。

这样就可以在显示“授权完成”后,点击进入你的微博界面weobolist.php,进去之后,你大吃一惊:相当的粗糙啊,没有样式,简单的html表单,哈哈,新浪微博的程序员怎么这么懒啊。赶紧发一条微博,测试一下吧,心里激动吧,呵呵。

我 们可以总结一下,其实蛮简单的,一共也就6个文件:config.php是配置文件,通过index.php进入到新浪微博的验证授权页面,同意授权之后 回到callback.php页面,点击进入我的微博,进到微博发表以及列表页weibolist.php,然后发表微博,就OK了。剩下的一个文件 weibooauth.php是一个类文件,装着许多类和函数,都是前面用到的,有兴趣的可以研究,可以不必理会它。还一个.DS_Stor不知道什么东西,打开是乱码,也不管了,估计没什么用的。

另外,提醒一下注意页面的编码格式,出现乱码的自己耐心的调试一下。

请问你callback.php文件里面下一步跳转的页面是什么啊?应该就是那个页面不存在吧。可以如下实现跳转:
$surl = "http://www.ifeng.com";

header("Location:$surl");

我现在也在做和你一样的事情,在输入账户信息后怎么跳转到我自己网站的页面而起还保证是登录状态一直没有能够解决,如果你解决了还请提点一下啊,哈哈哈。多谢多谢

skyaspnet您好,非常谢谢你!我的问题在您的帮助下已经解决了……谢谢您的帮助,谢谢!

回帖留待以后观看,不久后会涉及到这方面的问题,感谢楼主先发帖提问。

回帖留待以后观看,不久后会涉及到这方面的问题,感谢楼主先发帖提问。


不谋而合

参数不对? 

好帖,存下来 

谁的回复,还必须。。。。

太好了,先收藏起来

看过了流程,试一下

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles