Sina Weibo SDK usage instructions

Source: Internet
Author: User
Tags documentation mixed

When using the Sina Weibo SDK for development, it is obvious that Sina's SDK is more useful than Tencent's SDK. I was in the process of using the Sina Weibo SDK, encountered a lot of egg pain problem, make me super depressed. For example, the SDK to use it first to understand what is the jar package mode, what is the library mode, but also know the difference between the two, because his official API document that the two can not be mixed. Since it's not a mix, it's not as simple as choosing one, but it's not as easy as you can see from the documentation that you still need to mix the two external classes to some extent.

According to the normal thinking habit, since you have provided the SDK, also provides the jar package. It is clear that the SDK is imported into eclipse as a project to view, so that developers can easily view the source code, easy to quickly understand the interface and methods of the SDK. For the supplied jar, it is taken for granted that this is to be placed under the Libs folder and then added to the project you are developing. Moreover, the way to add jar packages to the Libs folder is undoubtedly a best practice. This makes it easy to share the source code when co-developing. If you use the library model, share the code, not only to share their own projects, but also to share the items marked as islibrary, many items back and forth export and import, it is very troublesome, and often error.


But the wonderful Sina SDK once again overturned the programmer's cognition. It does not think that the two should be separated, in fact, they have the jar package and the library model of the pattern to mix together, this is the root of all the trouble.


Even more ridiculous, as a platform to provide API interface to the outside, unexpectedly in the official document to tell the developer how to export the jar package, how to install the Eclipse plugin. Of course it says how to export the jar package, how to install the Eclipse plugin is related to the use of the SDK, but as an open platform, there is no ability to eliminate this complexity. You do not provide the SDK to reduce the technical threshold, so that developers get away to do more valuable things, this is good, do not study authorization certification, but instead of wasting a lot of time to study how to export the jar package, how to install the Eclipse plug-in. Can a little service consciousness AH.


I often have problems with the Sina Weibo SDK, many of which are caused by not following the steps required in the official documentation (but the steps in the official documentation are quite different), such as the "Cannot find the defined class" exception:

01-28 15:56:47.970:e/androidruntime (20190): Java.lang.noclassdeffounderror:com.weibo.android.r$style
01-28 15:56:47.970:e/androidruntime (20190): at 	com.weibo.net.weibodialog.<init> (weibodialog.java:54)
01-28 15:56:47.970:e/androidruntime (20190): at 	com.weibo.net.Weibo.dialog (weibo.java:353)
01-28 15:56:47.970:e/androidruntime (20190): at 	Com.weibo.net.Weibo.startDialogAuth (weibo.java:260)
01-28 15:56:47.970:e/androidruntime (20190): at 	com.weibo.net.Weibo.authorize (weibo.java:329)
01-28 15:56:47.970:e/androidruntime (20190): at 	com.weibo.net.Weibo.authorize (weibo.java:308)
01-28 15:56:47.970:e/androidruntime (20190): at 	com.logan.weibo.ui.AuthorizeActivity.onCreate ( AUTHORIZEACTIVITY.JAVA:66)
There are different ways to deal with this anomaly on the Internet, but they are not good, because Sina Weibo SDK is very wonderful, like a special. If you don't believe me, look at the document below and you'll believe it.


The following excerpt from the Sina Weibo Android Platform SDK documentation


Time

Document Version

Revising person

Note

2012/7/20

2.0.0

Luo Peng

Draft

2012/8/02

2.0.0

Zhang Xiaowei


Overview

The Weibo Android Platform SDK provides a document-friendly microblogging API call service for third-party microblogging applications, making it unnecessary for third-party clients to understand complex validation, API invocation procedures. and can realize the function of sharing to Weibo, can share text, or multimedia information to the built-in share page, and send to Weibo. Main class Description:

1. Weibo: micro-Blog API interface class, external to provide WEIBOAPI calls, including login, API calls, Weibo sharing and other functions.

2. Oauth2accesstoken: Encapsulates "Access_token", "expires_in", "Refresh_token", and provides

Their management functions

3. Utility: Tool class, provides the URL of the Encode,decode method.

4. Asyncweiborunner: The microblog API executes the class asynchronously, encapsulates the callback interface, and invokes the interface method in Weibo by creating a thread.

5. Httpmanager: The class that is responsible for communicating with the server, encapsulates the GET, POST request way, and provides the external image upload and so on function

6. WEIBOAPI: This class and its subclasses encapsulate the API interface methods provided by Sina Weibo.

7. Weiboexception: The micro-blog exception package class, encapsulated the micro-blog of the various anomalies.

8. Ssohandler: The single sign-On authentication class, provides the method of SSO login authentication externally.

SDK Usage Instructions 1. using weibo.sdk.android (does not include the SSO feature)

1.1 Import the SDK project into eclipse.

Select File->import->general->existing Projects into Workspace in Eclipse. Note: The encoding format for the SDK project is UTF-8. As shown in the figure:

Chart 2

1.2 Add the library to the project that needs to set the cost SDK.

Right-click Properties, Android. Set the library properties as shown in the figure:

Chart 3

The following permission must be included in the 1.3 manifest file:

<uses-permission android:name= "Android.permission.INTERNET" ></uses-permission>

<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE" ></uses-permission>

<uses-permission android:name= "Android.permission.WRITE_APN_SETTINGS" ></uses-permission>

<uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE" ></uses-permission>

1.4 If you want to use the jar package provided by the SDK directly in your own project, you can play the jar file in Eclipse's File->export->java->jar file. Suppose the name is Oauth20.jar, as shown in the following illustration: Note: The jar package mode and the library mode cannot be mixed, and this way the jar package is different from the auto-generated jar package in the library mode, which cannot get the assets directory into the jar file

Chart 4

The internal structure of the last generated jar is shown in the following figure:

Chart 5 2. Using Weibo.sdk.android.api

Weibo.sdk.android.api is based on the weibo.sdk.android, which provides some of the openapi of the Sina Weibo package interface for users to use.

2.1 Because the API SDK is developed on the basis of weibo.sdk.android, you need to import the Weibo.sdk.android SDK before using the API SDK, as described in the previous section.

2.2 Follow the steps in the previous section to import the API SDK, also need to set this SDK as library

2.3 In eclipse, into the new project's properties->android, add the library as shown in the following figure

2.4 If you want to use the jar package provided by the SDK directly in your own project, you can play the jar file in Eclipse's File->export->java->jar file, assuming the name is Oauth20-api.jar and the steps are 1.4. 3. Using Weibo.sdk.android.sso

3.1 Since the SSO SDK was developed on a weibo.sdk.android basis, it is necessary to import the Weibo.sdk.android SDK before using SSOSDK (if you want to use an API interface that is already encapsulated, You can also import Weibo.sdk.android.api), as described in the previous section.

3.2 Follow the steps in the previous section to import the SSO SDK, you will also need to set this SDK as library

3.3 In Eclipse, into the new project's properties->android, add the library as shown in the following figure

Chart 6

Once added, review the project's build path to ensure that Weibo.sdk.android.sso.jar and Weibo.sdk.android.jar have been introduced in the project as shown in the following diagram:

Chart 7

3.4 If you want to use the jar package provided by the SDK directly in your own project, you can also follow the steps below to generate the jar files you need, note: Jar package mode and library mode cannot be mixed

1) Install Net.sf.fjep.fatjar_0.0.31.jar:

A Place the above jar package into the Eclipse->plugins directory and restart eclipse

b Right click in the project, the following option to Build the Fat jar, indicating that the plug-in installation was successful

C If it does not appear, it will $eclipse _home\configuration\org.eclipse.update\platform.xml

Delete, and then restart Eclipse, perform the B step to check if the installation was successful

D If it is not successful, you can install this plugin online, the address of the plug-in is: Http://kurucz-grafika.de/fatjar, perform B-step check whether the installation is successful

E Generally through the above several steps, can be installed Fatjar, if not successful, then have to use the last move, another version of Eclipse, I use 3.7.2, no problem

Chart 8

2) Click the build Fat jar and follow the wizard step-by, when adding resources, The Oauth20.jar generated by the previous section (section 1.4) should be guaranteed to be checked in, as shown in the following figure, resulting in a jar, which will contain all the contents of Oauth20.jar, and the internal structure of the file, such as Diagram 5 ( If you want to use the interface provided by WEIBO.SDK.ANDROID.API, you will also need to tick the generated Oauth20-api.jar in section 2.4 When generating the jar file.

Chart 9

The resulting jar file is added as Lib into the built-in project, and the introduced library is deleted in the interface shown in icon 4.

when you're done, you can use it normally. 4. The use and modification of the SDK must comply with the Weibo developer agreement and the open source software agreement.

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.