PHP+新浪微博开放平台+新浪云平台(SAE)开发微博应用建立微博应用的过程
建立微博应用的过程
1、在微博开放平台上创建应用
首先登录你的微博。
在页面的最下端有个链接“开放平台”,单击此链接。
或者直接打开:http://open.weibo.com/,然后点击“我要开发应用”。
点击“创建应用”。
作为入门的尝试,我们开发的是“站内应用”。
按屏幕提示,输入一些必要信息:
在“应用信息”中,选择“基本信息”部分,记住App Key和App Secret的值。这两个值与授权有关,不急着搞清楚,后面编写程序时要用到。
创建应用最大的意义就在于,微博系统分配了App Key和App Secret两个值。现在,我们先放下这个工作,为编写代码做些准备。
2、下载SDK
到新浪微博开放平台的SDK下载页面http://open.weibo.com/wiki/SDK,找到PHP SDK的下载链接:
下载得到的是一个压缩文档,如下图所示。
在这些文件中,weibooauth.php提供了有关授权及实现微博应用功能的代码。这个文件中的内容不要做任何修改。
其他的文件实际上是为开发和运行程序微博应用提供的演示(Demo)。
将压缩文件解压,然后修改config.php中的代码,将可以作为你的第一个微博应用了。
config.php中的代码为:
[php] view plaincopyprint?
- define("WB_AKEY" , '请填入微博开放平台的APP Key' );
- define("WB_SKEY" , '请填入微博开放平台的APP Secret' );
- ?>
使用创建微博应用时的App Key和App Secret改写此文件。
例如,对前面创建的应用,改为
[php] view plaincopyprint?
- define("WB_AKEY" ,'2101372524' );
- define("WB_SKEY" , 'fa9f5111e317a942b895532b1f73837b' );
- ?>
这些代码将要上传到SAE云平台上,现在先放着,在SAE中创建应用后再说。
3、在SAE中创建应用
打开SAE的首页:http://sae.sina.com.cn/
因为已经有了微博帐号,选择“用微博帐号登录”。
然后出现的页面如下:
在界面中已经有了作者创建的两个应用。如果是第一次进入,“我创建的应用”部分是空的。
请点击“创建新应用”。
在“创建应用”的页面中,分别输入sinaapp.com的二级域名、应用名称以及应用描述。然后“创建应用”。
这时需要输入安全密码。安全密码是为部署代码时用的,可以在帐户设置中修改。
点击“安全验证”后,刚刚新建的应用出现在“我创建的应用”部分。
点击新建的应用,下面是应用的相关信息。点击“代码管理”……
接着选择“通过这里创建一个版本”……
版本号为1。
单击“创建”后,需要一点时间,系统将会为你布置好程序运行的环境。
记住这个版本应用的链接,这个链接可以直接使用,稍后还将要作为微博应用的“应用实际地址”使用。
现在需要“编辑代码”。
请注意“路径”右边的三个按钮。点击最右边的“上传”按钮,将在“2、下载SDK”部分下载并修改过的代码逐个上传。
上传index.php时,因为原先已经有此文件,不允许上传。需要先点右键,从菜单中点“删除”将原文件删除后再上传。
上传后的界面如下,打开“config.php”,确保App Key和App Secret是修改后的值。
大功已经告成。找到“代码管理”的页面,点击“链接”。
出现的页面如下。
“Use Oauth to login”中包含着个非常关键的概念,此处不表,先会做了,再看材料就好懂了。
然后进入了“应用授权”的页面。回想一下,使用别人开发的应用,是否需要你授权呢?点击“登录并授权”。
然后提示“授权完成,进入你的微博列表页面”。
点击链接,出现如下图所示的内容。看来这个应用的功能还是相当强的。能换头像、发微博和发带图片的微博,还能显示你和你关注的人的微博。
到目前为止,我们甚至没有写过一行PHP代码。其实,照这个流程先做下来,建立起应用的完整概念后再说。
到目前为止,我们看到的结果,仍然只是一个微博的Web界面,而不能称为微博应用。下面再做些工作,使其成为真正的微博应用后,我们再简单地理解一下代码。
4、使SAE中的应用成为微博应用
回顾在“1、在微博开放平台上创建应用”中有应用信息,当时我们记下了重要的两个值App Key和App Secret。
在该界面的右方,还有一个“编辑”链接。点击后,可以设置“站内应用地址”和“应用实际地址”。
“站内应用地址”处需要自己起一个个性化的域名,而“应用实际地址”处理输入的是SAE中“代码管理”处的“链接”,如下图所示(这张图前面出现过)。
之后,可以上传图片等,不说要述。最后,请保存信息。
保存后,就在当前页面,点击“站内应用地址”后面的链接。
顺着出现的链接一直点下去,你会发现,这就是真正的微博应用。
5、整理一下思路
有必要搞清这几个环节的关系。
首先在新浪开放开发平台中建立了一个微博应用。其中,最重要的是分配了App Key和App Secret值。微博是一个分布式的系统,信息的分享是靠用户及其他们之间的关注完成,并不是随便分享的。运行应用时,需要通过认证的方式将用户分清楚并且确保安全。这两个值很重要,更多的原理,会做应用后读一读文档就好了。
其次,一个应用需要代码。我们直接下载了PHP SDK中提供的Demo代码,作为我们第一个应用的业务逻辑。准备好的代码中,config.php中加入了App Key和App Secret。
再次,应用的代码需要在Web服务器上运行。我们没有采用经典的LAMP(Linux+ Apache+ Mysql+PHP)组合中用Apache作服务器,而是用新浪云平台解决。在云计算时代,让云为我们服务,优点不再说了。这种方案最大的好处是避免了麻烦的运行环境设置,处我们能够直接进入我们将代码上传后,Demo显示的结果实现了一个简单的应用:可以换头像、发微博和发带图片的微博,还能显示你和你关注的人的微博。
最后,在微博开放平台中,将SAE中应用的链接设置“应用实际地址”,再设一个“站内应用地址”。“站内应用地址”将应用会置入一个框架中,从而展示出的就是我们习惯了的,统一的“微博应用”风格。
这个应用是简单的,没有连接数据库,没有统计、分析,没有可视化的界面,但这是一个完整的应用。接下来,逐步学习如何建立更个性、实用的应用就可以了。另外,一个应用要提交审核并最终,还需要遵守一些规范,这些在Demo中也没有体现出来,请看相关文档吧。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

How to get real-name authentication on Jingdong Mall APP? Jingdong Mall is an online shopping platform that many friends often use. Before shopping, it is best for everyone to conduct real-name authentication so that they can enjoy complete services and get a better shopping experience. The following is the real-name authentication method for JD.com, I hope it will be helpful to netizens. 1. Install and open JD.com, and then log in to your personal account; 2. Then click [My] at the bottom of the page to enter the personal center page; 3. Then click the small [Settings] icon in the upper right corner to go to the setting function interface; 4. Select [Account and Security] to go to the account settings page; 5. Finally, click the [Real-name Authentication] option to fill in the real-name information; 6. The installation system requires you to fill in your real personal information and complete the real-name authentication

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using
