Introduction to Sina Weibo application demo

Source: Internet
Author: User
Tags learn php oauth

In fact, I am good at the technical means is Java, but if the use of Java development Sina Weibo application, you need to have their own personal space and independent domain name can be, make these things cost too high, and the company's host I also dare not public take private, no way, finally use a Sina development engine (Sina APP Engine SDK) To develop, this thing is supported by PHP, for this reason, I specifically read the quick introduction of PHP, began my Sina Weibo application development of the road of departure.

Digression: In fact, after reading Sina Weibo application API, want to get friends information, get their release of the latest several scarf, get comments and so on are very simple, in the SDK integration of existing functions, using Java code to publish a message is very simple, I am here to interrupt:

public static void UpdateStatus (string username, string pwd, String context) {Weibo Weibo = new Weibo (); Weibo.setuserid ( username); Weibo.setpassword (PWD); try {Status status = Weibo.updatestatus (context); System.out.println (Status.getid () + ":" + status.gettext () + "" + Status.getcreatedat ());} catch (Exception e) {e.printstacktrace ();}}

Because from the Learning API, deployment environment, the development of this code for a total of 2 hours, so I underestimated, think Sina's Scarf API development is so simple, but I encountered a few for the title, as mentioned above, I do not have the ability to publish Java scarf application, I want to do:

1. Learn PHP, recommend to see http://www.w3school.com.cn/php/index.asp, simple, fast enough to get started, enough standard.

2. Download the Sina App Engine sdk:http://sae.sina.com.cn/?m=sdk, download the Windows version of the available

3. Download php sdk:http://open.t.sina.com.cn/wiki/index.php/sdk#php, I download the time there are two, are supported through the OAuth authentication method, casually under the first, support picture upload. However, later found that the recommended support SAE version, after all, our demo is in the SAE above developed.

4. In the Sina App Engine SDK Registration (I can only register experience account, but enough, can use 5 days, then registration CAN): This does not need me to teach

5. Create an app in the Sina app Engine SDK: Creating an app in the admin interface can be. Http://xhprof.tools.sinaapp.com/demo_beta/This is a three minute video to create an application, and you can learn more about it here.

The above process you are ready, if you have seen the fifth step of the video, we want to create a demo to run, this demo is to use the OAuth way of authorization, as we usually play in other applications, there will be a licensing process, after the authorization, you can obtain the authorized user information, Of course, this demo is just a simple authorization +helloworld process. After the application I have not done, then add, don't talk nonsense, cut to the chase:

Formal Demo Development Steps:

1. The 3rd step of the above process you have downloaded the PHP SDK. This SDK after decompression has a Weibodemo folder, will all the files inside copy to the 2nd step download of the Sina App Engine SDK unpacked files apps, This is the folder where the index.php in the 4th step is shown in the video.

2. To http://open.t.sina.com.cn/apps/to create an application, the application of the application address is to create the application in the Sina app engine when the two domain name, such as mine is http://bentest.sinaapp.com. After you create the application you will get the app key and app Secret

3. Modify the Sina App Engine SDK file apps file config.php file, the 2nd step to get the key value set to this config.php, this is a person will be set to not say.

4. Modify the Sina App Engine SDK file apps file index.php file, the 13th line to modify the last parameter to your domain +callback.php path, put an example out of all know: $aurl = $o-> Getauthorizeurl ($keys [' Oauth_token '], false, ' http://bentest.sinaapp.com/callback.php '); Note that http://bentest.sinaapp.com is the two-level domain name of the application you created in the Sina App Engine SDK .

5. The operation is completed.

I used to run this demo, there has been a failure to authorize the phenomenon, the main reason for the failure of Authorization is $o->getrequesttoken () This line of statements did not get the parameter value, the search for a half-day found my reason is my app key and app secret wrong. Because I use the app key and app secret is Sina App Engine SDK This development platform of key and secret, no wonder I debug for a long time can not get out, later I use The formal demo development step of the 2nd step to get there is no problem.

PS: If the callback.php path is not written right, may also appear authorization failure phenomenon, mainly cross-domain problems, this I was online to find someone met, I did not encounter.

Finally can start to do their own application, but also do not have much time to learn PHP, can only use a limited time to slowly start behind the journey ...

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.