php+ Sina Weibo open platform + Sina Cloud Platform (SAE) to develop micro-blogging application--the process of establishing microblog application

Source: Internet
Author: User
Tags define config log php code php define domain domain name
the process of establishing a microblog application 1. Create application on Weibo open platform

First log in to your microblog.

At the bottom of the page there is a link to "open platform", click this link.

or open it directly: http://open.weibo.com/, and then click on "I want to develop apps."

Click "Create Application".

As an attempt to get started, we developed the "in-Station application".

Follow the on-screen prompts to enter some of the necessary information:

In application information, select the "Basic Information" section to remember the value of the app key and app secret. These two values are related to authorization and are not in a hurry to figure out what to use when writing a program later.

The biggest implication of creating applications is that the microblogging system allocates two values for app key and app secret. Now, let's just drop the job and get ready to write the code.

2, download the SDK

To the Sina Weibo open Platform SDK download page Http://open.weibo.com/wiki/SDK, find the PHP SDK download link:

The download is a compressed document, as shown in the following figure.

In these files, Weibooauth.php provides code to authorize and implement the microblogging application functionality. Don't make any changes to the contents of this file.

Other files are actually demos for the development and running of program microblogging applications.

Unzip the compressed file and then modify the code in config.php, which will be used as your first microblogging application.

The code in config.php is:

[PHP]View Plaincopyprint?
    1. <?php
    2. Define ("Wb_akey", ' please fill in the open platform of the app Key ');
    3. Define ("Wb_skey", ' please fill in the Open platform of App Secret ');
    4. ?>
<textarea class="php" name="code" readonly=""><?php define ("Wb_akey", ' please fill in the Open Platform App Key '); Define ("Wb_skey", ' please fill in the Open Platform App Secret ');?></textarea>
Rewrite this file with the app key and app secret when you create the microblogging application.

For example, for the previously created application, change to

[PHP]View Plaincopyprint?
    1. <?php
    2. Define ("Wb_akey", ' 2101372524 ');
    3. Define ("Wb_skey", ' fa9f5111e317a942b895532b1f73837b ');
    4. ?>
<textarea class="php" name="code" readonly=""><?php define ("Wb_akey", ' 2101372524 '); Define ("Wb_skey", ' fa9f5111e317a942b895532b1f73837b ');</textarea>

The code is going to be uploaded to the SAE cloud platform, and now put it on before you create the application in the SAE.

3. Create application in SAE

Open the SAE home: http://sae.sina.com.cn/

Because already has the microblog account number, chooses "uses the micro-blog account log In".

Then the page appears as follows:

There are two applications created by the author in the interface. If this is the first time, the "I Created Apps" section is empty.

Please click "Create New Application".

In the Create Application page, enter the sinaapp.com level two domain name, the application name, and the application description, respectively. Then "Create Application."

Then you need to enter a secure password. A secure password is used for deploying code and can be modified in the account settings.

After you click Security Verification, the newly created application appears in the "I Create Apps" section.

Click on the new application, the following is the application of relevant information. Click on "Code Management" ...

Then select "Create a version from here" ...

The version number is 1.

When you click Create, you need a little time, and the system will set up the environment for your program to run.

Remember the link to this version, which can be used directly, and will be used as a "practical address" for microblogging applications later.

Now you need to "edit code."

Notice the three buttons to the right of the path. Click on the rightmost "upload" button, will be in the "2, download the SDK" part of the download and modified code upload one by one.

Upload index.php, because the original already have this file, not allowed to upload. You need to first right-click, from the menu point "Delete" to delete the original file and then upload.

After uploading the interface below, open "config.php" to ensure that app key and app secret are modified values.

The success has already been done. Find the "Code Management" page and click on "link".

The page appears as follows.

"Use Oauth to login" contains a very critical concept, not here, the first will be done, and then look at the material is understood.

It then goes to the "Apply Authorization" page. Looking back, do you need to authorize the use of other developed applications? Click "Sign in and authorize".

Then prompt "Authorization complete, enter your microblog list page".

Click on the link to see what is shown in the following figure. It seems that the function of this application is still quite strong. Micro blogs that can change avatars, tweet and send pictures can also show you and the people you care about.

So far, we haven't even written a single line of PHP code. In fact, follow this process first, set up the full concept of application.

So far, the results we've seen are still just a microblog web interface, not a microblog application. After doing some work to make it a real microblogging application, let's simply understand the code.

4, so that the application of SAE as a micro-bo application

We reviewed the application information in "1, creating applications on Weibo open platforms" when we noted the important two values of app key and app Secret.

On the right side of the interface, there is also an "edit" link. After clicking, you can set the "Site application Address" and "Apply the actual address".

"Site application Address" needs to own a personalized domain name, and "Apply the actual address" processing input is the SAE "code management" in the "link", as shown in the following figure (this picture appears earlier).

After that, you can upload pictures and so on, not to mention. Finally, please save the information.

After saving, on the current page, click on the link in the "Site application Address".

Follow the link that appears and you will find that this is the real microblogging application.

5, tidy up the idea

It is necessary to understand the relationship between these several links.

First in Sina Open development platform to establish a micro-blog application. Among them, the most important is the allocation of the app key and app secret values. Weibo is a distributed system in which information sharing is accomplished by the attention of users and others, and is not casually shared. When running an application, you need to be authenticated to make sure that users are clearly divided and secure. These two values are very important, more principles, will be done after the application read the document is good.

Second, an application requires code. We have directly downloaded the demo code provided in the PHP SDK as our first application of the business logic. In the prepared code, the app key and app Secret are added to the config.php.

Again, the applied code needs to run on the Web server. We did not use the classic lamp (linux+ apache+ mysql+php) in the combination of Apache server, but with the Sina Cloud platform solution. In the era of cloud computing, let cloud for our service, the advantages are no longer said. The biggest benefit of this scheme is that it avoids the hassle of running environment settings, we are able to go directly to our code upload, the results of the demo display to achieve a simple application: You can change the avatar, micro-blog and send a picture of the microblog, but also to show you and the people you care about the microblog.

Finally, in the microblogging open platform, the application of the SAE link to "Apply the actual address", and then set a "Site application address." "Site application Address" will be placed into a framework, so as to show that we are accustomed to the unified "microblogging application" style.

This application is simple, no connection database, no statistics, analysis, no visual interface, but this is a complete application. Next, gradually learn how to build a more personalized, practical application can be. In addition, an application to submit audits and eventually, also need to adhere to a number of specifications, these are not reflected in the demo, please see the relevant documents.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.