Renren Social Plugin SDK Developer Manual.Android.2.0.1

tibburfrogtownMobile - Wireless

Dec 14, 2013 (3 years and 7 months ago)

103 views

Developer Manual : Renren Social Plugin SDK
Android v2.0.1
I.
Features

Lightweight interface: including all the GUI functional components such
as login components, register components, upload photos components,
publish feeds components which can be shown in any view of the app on
Android freely.

Easily called: after a simple configuration and adding a few lines of codes,
you have already finished accessing and calling the perfect packaged
interface then you can enjoy the service provided by Renren.

Lightweight access: SDK is very tiny and it takes up very little memory
while running.
II.
Introduction
This manual is intended to be a general guide for developers who want to use
Renren Social Plugin SDK. In order to use this SDK, you should make sure that
Android SDK is installed on your computer. For more information about android
SDK, please refer to
http://developer.android.com.
III.
Function
Interface List
1.
Definition of RenrenMicroClientCenter Interfaces
Function
Method Name
Initialization
public void setClientInfo(String apiKey,
String appSecret,
String appId)
Initialization from launcher Activity
public void initFromLauncher(Activity
activity)
set privileges
public void initOAuthRequest
(PRIVILEGE_TYPE[]
privileges,
boolean readOnly,
boolean switchUser)
register
public void registe()
login
public void login (Activity activity)
logout
public void logout()
is current user login
public boolean hasLogin()
get user info
public UserInfo getUserInfo()
2.
Definition of UGC Interfaces
Function
Method Name
launch upload photo Activity
UploadPhotoActivity:
public static void start(Activity activity,
File file,
File fileShow,
String caption,
String url)
launch publish feed Activity
FeedActivity:
public static void start(Context context,
PublishFeedRequest request)
3.
Definition of Payment Interfaces
Function
Method Name
launch payment Activity
PaymentActivity:
public static void start(Context context,
String service,
String v_p,
String partnerId,
String secId,
String outOrderId,
String goodsTitle,
double totalFee,
long goodsQuantity,
String appChannel,
String orderTime,
double goodsPrice,
String notifyUrl,
String callBackUrl,
String partnerUrl,
String payKey)
4.
Extension API List
Function
Method Name
get friends list
request:GetFriendsRequest
response:GetFriendsResponse
set status
request:SetStatusRequest
response:SetStatusResponse
publish customized feed
request:PublishFeedRequest
response:PublishFeedResponse
publish photo
request:UploadBinPhotoRequest
response:UploadBinPhotoResponse
check in
request:CheckinRequest
response:CheckinResponse
upload game scores
request:ScoreUploadRequest
response:ScoreUploadResponse
IV.
Getting Ready
1.
Copy rmc_lib_2.0.1.jar to libs folder in your project. If your project does not
have a libs folder, right mouse click-> select new -> select Folder -> input
“libs” -> click Finish to create a libs Folder.

Then select rmc_lib_2.0.1.jar in your project, right mouse click -> select
Build Path -> select Add To Build Path.
2.
Add necessary code in your AndroidManifest.xml:
<!-- Add follow code in application Node -->
<activity android:name="com.renren.mobile.tinyclient.TinyClientActivity"
android:configChanges="orientation|keyboardHidden|navigation">
</activity>
<activity android:name="com.renren.mobile.rmsdk.coreimpl.auth.LoginActivity" >
</activity>
<activity android:name="com.renren.mobile.rmsdk.oauthimpl.auth.OAuthActivity" >
</activity>
<activity
android:name="com.renren.mobile.rmsdk.oauthimpl.auth.ChooseAccountActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
<activity android:name="com.renren.mobile.tinyclient.status.StatusActivity" >
</activity>
<activity android:name="com.renren.mobile.rmsdk.externaltools.feed.FeedActivity"
android:configChanges="orientation|keyboardHidden|navigation"></activity>
<activity
android:name="com.renren.mobile.rmsdk.externaltools.photos.UploadPhotoActivity"
android:configChanges="orientation|keyboardHidden|navigation" >
</activity>
<activity android:name="com.renren.mobile.tinyclient.payment.PaymentActivity"
android:configChanges="orientation|keyboardHidden|navigation">
</activity>
<!-- Add follow code in manifest Node -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
3.
Your AndroidManifest.xml should looks like this when you add the code
above:

V.
Initialization

Before use API, RenrenMicroClientCenter must be initialized. You can put
initialization code in your Activity’s onCreate method. You need to set OAuth
privilege after initialization. APP can choose privilege according to its needs,
privilege list can be found in PrivilegeUtil.java.
RenrenMicroClientCenter mRMCenter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

...

mRMCenter =
RenrenMicroClientCenter
.getInstance(this);
mRMCenter.setClientInfo(API_KEY, SECRET_KEY, APP_ID);
PRIVILEGE_TYPE[] privileges =
new PRIVILEGE_TYPE[]{PRIVILEGE_TYPE.write_resouce};
mRMCenter.initOAuthRequest(privileges, false, false);
}
VI.
Launch from Renren Android Client
To login immediately after launch from Renren Android Client, APP need to
initialize RenrenMicroClientCenter and call initFromLauncher method in Launcher
Activity.
App can set AuthVerifyListener to observe login process.
Example:

m R M C e n t e r = R e n r e n M i c r o C l i e n t C e n t e r.g e t I n s t a n c e ( t h i s );
m R M C e n t e r.s e t C l i e n t I n f o ( A P I _ K E Y, S E C R E T _ K E Y, A P P _ I D );
P R I V I L E G E _ T Y P E [ ] p r i v i l e g e s =
n e w P R I V I L E G E _ T Y P E [ ] { P R I V I L E G E _ T Y P E.w r i t e _ r e s o u c e };
m R M C e n t e r.i n i t O A u t h R e q u e s t ( p r i v i l e g e s, f a l s e, f a l s e );
m R M C e n t e r.s e t A u t h V e r i f y L i s t e n e r ( n e w A u t h V e r i f y L i s t e n e r ( ) {

@ O v e r r i d e
p u b l i c v o i d o n A u t h V e r i f y S u c c e s s ( ) {
T o a s t.m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ),
"a u t h v e r i f y s u c c e s s",
T o a s t.L E N G T H _ L O N G ).s h o w ( );
}

@ O v e r r i d e
p u b l i c v o i d o n A u t h V e r i f y F a i l e d ( ) {
}
} );
m R M C e n t e r.i n i t F r o m L a u n c h e r ( t h i s );
V I I.
F u n c t i o n R e f e r e n c e:
1.
I n t e g r a t e M i c r o C l i e n t B u t t o n

T o i n t e g r a t e r m c _ l i b _ 2.0.1.j a r, a l l y o u n e e d t o d o i s t o a d d
L a u c h T i n y C l i e n t B u t t o n t o y o u r l a y o u t, y o u c a n d o t h i s e i t h e r b y e d i t y o u r j a v a c o d e
o r l a y o u t.x m l:

C o d e:


L a u c h T i n y C l i e n t B u t t o n l a u c h T i n y C l i e n t B u t t o n = n e w L a u c h T i n y C l i e n t B u t t o n ( … );
v i e w.a d d V i e w ( l a u c h T i n y C l i e n t B u t t o n );
!
XML:


< c o m.r e n r e n.m o b i l e.t i n y c l i e n t.v i e w.L a u c h T i n y C l i e n t B u t t o n
a n d r o i d:i d ="@ + i d/l a u c h _ b u t t o n"
a n d r o i d:l a y o u t _ w i d t h ="w r a p _ c o n t e n t"
a n d r o i d:l a y o u t _ h e i g h t ="w r a p _ c o n t e n t"/>
2.
L o g i n

S D K w i l l d e a l w i t h l o g i n i n m o s t c a s e s, s u c h a s m i c r o c l i e n t, u p l o a d p h o t o,
p u b l i s h f e e d. B u t, w h e n y o u w a n t t o h a n d l e l o g i n y o u r s e l f, y o u c a n u s e t h e l o g i n
m e t h o d. Y o u c a n s e t L o g i n L i s t e n e r t o o b s e r v e l o g i n p r o c e s s:

m R M C e n t e r.s e t L o g i n L i s t e n e r ( n e w L o g i n L i s t e n e r ( ) {
@ O v e r r i d e
p u b l i c v o i d o n L o g i n S u c c e s s ( ) {
T o a s t.m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ),
"l o g i n s u c c e s s", T o a s t.L E N G T H _ L O N G ).s h o w ( );
}

@ O v e r r i d e
p u b l i c v o i d o n L o g i n C a n c e l e d ( ) {
T o a s t.m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ),
"l o g i n c a n c e l", T o a s t.L E N G T H _ L O N G ).s h o w ( );
}
} );

m R M C e n t e r.l o g i n ( A c t i v i t y.t h i s );

A n d a d d f o l l o w i n g c o d e i n y o u r A c t i v i t y ’ s o n A c t i v i t y R e s u l t m e t h o d:



@ O v e r r i d e
p r o t e c t e d v o i d o n A c t i v i t y R e s u l t ( i n t r e q u e s t C o d e, i n t r e s u l t C o d e, I n t e n t d a t a ) {
m R M C e n t e r.o n A c t i v i t y R e s u l t ( r e q u e s t C o d e, r e s u l t C o d e, d a t a );
}
3.
A b o u t S S O
W h e n R e n r e n o f f i c i a l C l i e n t i s i n s t a l l e d, S o c i a l p l u g i n l o g i n o f f i c i a l c l i e n t ’ s a c c o u n t b y
d e f a u l t.
D e v e l o p e r c a n c a l l l o g i n ( A c t i v i t y a c t i v i t y, b o o l e a n e n a b l e S w i t c h ) t o l a u n c h a n d i a l o g t o
c h o o s e w h e t h e r t o l o g i n o f f i c i a l c l i e n t ’ s a c c o u n t o r l o g i n a n o t h e r a c c o u n t. T h e f i r s t p a r a m e t e r i s
t h e c u r r e n t a c t i v i t y, t h e s e c o n d i s i f t h e b e l o w f e a t u r e i s e n a b l e d.
4.
R e g i s t e r

m R M C e n t e r.r e g i s t e ( );
4.
L o g o u t

m R M C e n t e r.l o g o u t ( );
5.
G e t U s e r I n f o
U s e r I n f o c o n t a i n s m a n y u s e f u l i n f o r m a t i o n s s u c h a s u s e r i d, u s e r n a m e, y o u c a n
g e t u s e r ’ s i n f o a s f o l l o w s:
U s e r I n f o u s e r I n f o = m R M C e n t e r.g e t U s e r I n f o ( );
6.
U p l o a d P h o t o

F o l l o w i n g c o d e c a n l a u n c h a n A c t i v i t y t h a t c o u l d u p l o a d a p h o t o w i t h p r e v i e w:
F i l e f i l e = n e w F i l e ("…");
U p l o a d P h o t o A c t i v i t y.s t a r t ( A c t i v i t y.t h i s, f i l e, f i l e,
"u p l o a d p h o t o", "w w w.r e n r e n.c o m");
7.
P u b l i s h F e e d

F o l l o w i n g c o d e c a n l a u n c h a n A c t i v i t y t h a t c o u l d p u b l i s h a c u s t o m n e w s f e e d:
P u b l i s h F e e d R e q u e s t r e q u e s t =
n e w P u b l i s h F e e d R e q u e s t.B u i l d e r (
"T i t l e",
"C o n t e n t" ,
"h t t p://w w w.r e n r e n.c o m")
.setActionName("visit us").setActionLink("http://www.renren.com")
.setImageSrc("http://s.xnimg.cn/imgpro/logo/v6_2.png")
.setMessage("message").create();
FeedActivity.start(TinyClientTestActivity.this, request);
8.
Payment
try {
PaymentActivity.start(
Tiny_client_demoActivity.this,
"3g.payment.create",
"1.0",
"100001",
"MD5",
System.currentTimeMillis() + "",
goodsTitleStr,
goodsPrice * goodsQuantity,
goodsQuantity,
"Android",
Da t e F o r ma t.f o r ma t ("y y y y - MM- d d h h:mm:s s",
System.currentTimeMillis()).toString(),
goodsPrice,
null,
null,
null,
"paykey");
} catch (RRException e) {
e.printStackTrace();
}
9.
S S O L o g o u t
W h e n R e n r e n A n d r o i d C l i e n t i s i n s t a l l e d o n u s e r ’ s p h o n e, s o c i a l p l u g i n w i l l t r y
S S O f i r s t. W h e n R e n r e n A n d r o i d C l i e n t i s l o g o u t, i t w i l l s e n d a n b r o a d c a s t. I f y o u
w a n t t o d o s o m e t h i n g s u c h a s l o g o u t s o c i a l p l u g i n, y o u n e e d t o r e g i s t e r y o u r o w n
b r o a d c a s t r e c e i v e r.

< r e c e i v e r
a n d r o i d:n a m e =
"c o m.r e n r e n.m o b i l e.r m s d k.o a u t h i m p l.a u t h.L o g o u t B r o a d C a s t D i s p a c t c h e r" >
< i n t e n t - f i l t e r >
< a c t i o n a n d r o i d:n a m e =
"c o m.r e n r e n.r e n r e n _ a c c o u n t _ m a n a g e r.R E N R E N _ M O B I L E _ L O G I N _ B R O A D C A S T"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:name=
"com.renren.mobile.rmsdk.oauthimpl.auth.LogoutBroadCastDispactcher" >
<intent-filter>
<action android:name=
"com.renren.renren_account_manager.RENREN_MOBILE_LOGOUT_BROADCAST
" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:name=
"your.broadcast.receiver" >
<intent-filter>
<action android:name=
"com.renren.sso.RENREN_LOGOUT_BROADCAST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
VIII.
Extension API

1.
Use extension API

Wh e n u s e r i s l o g g i n g i n, t a k e f o l l o wi n g s t e p s t o s e n d a n API r e q u e s t t h r o u g h
Re n r e n Mi c r o Cl i e n t Ce n t e r:
a)
Form an API request, parameters in Builder method is required, parameter in
setters is optional, take upload photo as example:


U p l o a d B i n P h o t o R e q u e s t r e q u e s t =
n e w U p l o a d B i n P h o t o R e q u e s t.B u i l d e r ( f i l e ).s e t C a p t i o n ("c a p t i o n").c r e a t e ( );

b )
Use RenrenMicroClientCenter to send request, <T> T request
(RequestBase<T> request) is synchronized method:
try {
UploadBinPhotoResponse response = mRMCenter.request(request);
} catch (RRException e) {
e.printStackTrace();
}
c)
Use <T extends ResponseBase> void request
(final RequestBase<T> request, final ResponseListener<T> listener) to send
unsynchronized method:

m R M C e n t e r.r e q u e s t ( r e q u e s t, n e w R e s p o n s e L i s t e n e r < U p l o a d B i n P h o t o R e s p o n s e > ( ) {

@ O v e r r i d e
p u b l i c v o i d o n C o m p l e t e ( U p l o a d B i n P h o t o R e s p o n s e a r g 0 ) {
}
@ O v e r r i d e
p u b l i c v o i d o n R R E x c e p t i o n ( R R E x c e p t i o n a r g 0 ) {

}
} );
2.
Extension API List
Function
Request
Response
get friends list
GetFriendsRequest
GetFriendsResponse
set status
SetStatusRequest
SetStatusResponse
publish customized feed
PublishFeedRequest
PublishFeedResponse
publish photo
UploadBinPhotoRequest
UploadBinPhotoResponse
check in
CheckinRequest
CheckinResponse
upload game scores
ScoreUploadRequest
ScoreUploadResponse
IX.
Encapsulate API
You can encapsulate API on your own. You must clarify API’s request and
response parameters before encapsulation. There are two classes for each API: request
and response.

Request must inherit from RequestBase, and pass the right template param. Use
annotation @RestMethodName to declare API method name. Use annotation
@RequiredParam to declare required parameters, use annotation @OptionalParam to
declare optional parameters.
Example:
/**
* Example Only
*/
@RestMethodName("example.test")
public class ExampleRequest extends RequestBase<ExampleResponse> {

@RequiredParam("example_required_param")
private int exampleRequiredParam;

public int getExampleRequiredParam(){
return this.exampleRequiredParam;
}

p u b l i c v o i d s e t E x a m p l e R e q u i r e d P a r a m ( i n t e x a m p l e R e q u i r e d P a r a m ) {
t h i s. e x a m p l e R e q u i r e d P a r a m = e x a m p l e R e q u i r e d P a r a m;
}

}
R e s p o n s e m u s t i n h e r i t f r o m R e s p o n s e B a s e. U s e a n n o t a t i o n @ J s o n P r o p e r t y t o
d e c l a r e r e s p o n s e f i e l d s. F i e l d s c a n b e L i s t t h a t i n h e r i t f r o m R e s p o n s e B a s e.
E x a m p l e:

/* *
* E x a m p l e O n l y
*/
p u b l i c c l a s s E x a m p l e R e s p o n s e e x t e n d s R e s p o n s e B a s e {

@ J s o n P r o p e r t y ("e x a m p l e _ r e s p o n s e _ i t e m")
p r i v a t e i n t e x a m p l e R e s p o n s e I t e m;
p u b l i c i n t g e t E x a m p l e R e s p o n s e I t e m ( ) {
r e t u r n t h i s.e x a m p l e R e s p o n s e I t e m;
}
p u b l i c v o i d s e t E x a m p l e R e s p o n s e I t e m ( i n t e x a m p l e R e s p o n s e I t e m ) {
t h i s.e x a m p l e R e s p o n s e I t e m = e x a m p l e R e s p o n s e I t e m;
}
}
U s e R e n r e n M i c r o C l i e n t C e n t e r t o s e n d r e q u e s t:

E x a m p l e R e q u e s t r e q u e s t = n e w E x a m p l e R e q u e s t ( );
r e q u e s t.s e t E x a m p l e R e q u i r e d P a r a m ( 0 );
t r y {
E x a m p l e R e s p o n s e r e s p o n s e = m R M C e n t e r.r e q u e s t ( r e q u e s t );
} c a t c h ( R R E x c e p t i o n e ) {
e.p r i n t S t a c k T r a c e ( );
}
X.
U p g r a d e f r o m 1.0.1
Y o u n e e d f o l l o w t h e s e s t e p s t o u p g r a d e s o c i a l p l u g i n f r o m 1.0.1:
1.
R e p l a c e R M C o n n e c t C e n t e r t o R e n r e n M i c r o C l i e n t C e n t e r
Replace all RMConnectCenter to RenrenMicroClientCenter, Replace
R M C o n n e c t C e n t e r.g e t I n s t a n c e ( A c t i v i t y.t h i s ) t o
R e n r e n M i c r o C l i e n t C e n t e r.g e t I n s t a n c e ( A c t i v i t y.t h i s );

2.
A d d P r i v i l e g e s e t t i n g s
I n i t i a l i z a t i o n b e f o r e:

m R M C e n t e r = R M C o n n e c t C e n t e r.g e t I n s t a n c e ( t h i s );
m R M C e n t e r.s e t C l i e n t I n f o ( A P I _ K E Y, S E C R E T _ K E Y, A P P _ I D );
R e p l a c e t o:

m R M C e n t e r = R e n r e n M i c r o C l i e n t C e n t e r.g e t I n s t a n c e ( t h i s );
m R M C e n t e r.s e t C l i e n t I n f o ( A P I _ K E Y, S E C R E T _ K E Y, A P P _ I D );
PRIVILEGE_TYPE[] privileges =
new PRIVILEGE_TYPE[]{PRIVILEGE_TYPE.write_resouce};
mRMCenter.initOAuthRequest(privileges, false, false);
mRMCenter.setAuthVerifyListener(new AuthVerifyListener() {

@ O v e r r i d e
p u b l i c v o i d o n A u t h V e r i f y S u c c e s s ( ) {
T o a s t.m a k e T e x t ( g e t A p p l i c a t i o n C o n t e x t ( ),
"a u t h v e r i f y s u c c e s s",
T o a s t.L E N G T H _ L O N G ).s h o w ( );
}

@ O v e r r i d e
p u b l i c v o i d o n A u t h V e r i f y F a i l e d ( ) {
}
} );
m R M C e n t e r.i n i t F r o m L a u n c h e r ( t h i s );
3.
M o d i f y A n d r o i d M a n i f e s t.x m l
A d d f o l l o w i n g c o d e u n d e r a p p l i c a t i o n n o d e:
< a c t i v i t y a n d r o i d:n a m e ="c o m.r e n r e n.m o b i l e.r m s d k.o a u t h i m p l.a u t h.O A u t h A c t i v i t y" >
</a c t i v i t y >
< a c t i v i t y
a n d r o i d:n a m e ="c o m.r e n r e n.m o b i l e.r m s d k.o a u t h i m p l.a u t h.C h o o s e A c c o u n t A c t i v i t y"
a n d r o i d:t h e m e ="@ a n d r o i d:s t y l e/T h e m e.T r a n s l u c e n t.N o T i t l e B a r">
</a c t i v i t y >
A d d f o l l o w i n g c o d e u n d e r m a n i f e s t n o d e:

< u s e s - p e r m i s s i o n a n d r o i d:n a m e ="a n d r o i d.p e r m i s s i o n.G E T _ A C C O U N T S" />

< u s e s - p e r m i s s i o n a n d r o i d:n a m e ="a n d r o i d.p e r m i s s i o n.U S E _ C R E D E N T I A L S" />
< u s e s - p e r m i s s i o n a n d r o i d:n a m e ="a n d r o i d.p e r m i s s i o n.M A N A G E _ A C C O U N T S" />
XI.
ScreenShot
1.
Micro Client Home
2.
Login
3.
Upload Photo
4.
Publish Feed