教程演示sociallibs在Android的不同特点

教程演示sociallibs在Android的不同特点

本文介绍了示例项目/教程演示sociallibs在Android的不同特点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于sociallib:

http://www.androidlibs.com/sociallib.html

HTTP://$c$c.google.com/p/ sociallib /维基/ AdvancedGuide

HTTP://$c$c.google.com/p/ sociallib /维基/ SocialLibGuide

SocialLib目的是使社会的发展更容易的应用程序。目前,社会库可访问以下的社交网络:

SocialLib aims to make the development of Social apps much more easier. Currently, Social Lib provides access to the following social networks :

  • 的Facebook
  • 在微博
  • 谷歌
  • 巴兹
  • 在LinkedIn

现在我的情况:

我创建了微博,Facebook的应用程序和生成的API和秘密密钥。

I created apps in Twitter, facebook and generated API and secret keys.

我试图按照指南中SocialLibs的wiki页面。

I tried to follow the guide in the wiki page of SocialLibs.

但不幸的是我坚持..我需要有人来指向连接并发布至Facebook的工作源,微博...等

But unfortunately i'm stuck.. I need someone to point to a working source of connection and posting to facebook, twitter...etc

下面是code,我试过了..可有人纠正我,如果有一些错误..?
的Java code:

Here is the code that i tried out.. can someone correct me if there is some errors..?
Java Code:

package com.schogini.socialib2x;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.scribe.oauth.Token;
import org.xml.sax.SAXException;

import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.expertiseandroid.lib.sociallib.connectors.SocialNetworkHelper;
import com.expertiseandroid.lib.sociallib.connectors.TwitterConnector;
import com.expertiseandroid.lib.sociallib.exceptions.NotAuthentifiedException;
import com.expertiseandroid.lib.sociallib.model.twitter.TwitterUser;

public class mainAct extends Activity {

    String CONS_KEY = "sdasdadsfdafafafwrfgsdfadfafasfasfsaf";
    String CONS_SEC = "sdasdadsfdafafafwrfgsdfadfafasfasfsaf";
    String CALLBACK = "http://schogini.in";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TwitterConnector twitter = SocialNetworkHelper.createTwitterConnector(CONS_KEY, CONS_SEC, CALLBACK);
        try {
            twitter.requestAuthorization(this);
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthNotAuthorizedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            twitter.authorize(this);
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthNotAuthorizedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Token at = twitter.getAccessToken();
        String token = at.getToken(); //You can store these two strings
        String secret = at.getSecret();//in order to build the token back

        Token myAccessToken = new Token(token, secret);
        twitter.authentify(myAccessToken);

        TwitterUser me;
        int nbFollowers = 0;
        String nickname = null;
        try {
            me = twitter.getUser();
            nickname = me.getUsername(); //Some information is available through method calls
            nbFollowers = me.nbFollowers; //Some is available through object fields
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotAuthentifiedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //Retrieves the current user


        TextView tv = (TextView) findViewById(R.id.text1);
        tv.setText("You are logged in as " + nickname + " and you have " + nbFollowers + " followers"); //Now we can print the information we retrieved onscreen

        try {
            twitter.tweet("Tweeting from code");
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotAuthentifiedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //A simple tweet

        try {
            twitter.logout(this);
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotAuthentifiedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //Providing this code is located in an Activity (or Context) class
    }

}

清单code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.schogini.socialib2x"
      android:versionCode="1"
      android:versionName="1.0">

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".mainAct" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <data android:scheme="testapp" android:host="twitter" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

下面是 LogCat中输出:

04-30 17:08:26.584: INFO/ActivityManager(60): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.schogini.socialib2x/.mainAct } from pid 374
04-30 17:08:26.754: DEBUG/AndroidRuntime(374): Shutting down VM
04-30 17:08:26.825: INFO/ActivityManager(60): Start proc com.schogini.socialib2x for activity com.schogini.socialib2x/.mainAct: pid=384 uid=10040 gids={3003, 1015}
04-30 17:08:26.855: INFO/AndroidRuntime(374): NOTE: attach of thread 'Binder Thread #3' failed
04-30 17:08:26.894: DEBUG/dalvikvm(374): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 3ms+2ms
04-30 17:08:26.985: DEBUG/jdwp(374): Got wake-up signal, bailing out of select
04-30 17:08:26.985: DEBUG/dalvikvm(374): Debugger has detached; object registry had 1 entries
04-30 17:08:30.385: WARN/Resources(384): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f050000}
04-30 17:08:30.444: ERROR/dalvikvm(384): Could not find class 'oauth.signpost.commonshttp.CommonsHttpOAuthConsumer', referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.<init>
04-30 17:08:30.444: WARN/dalvikvm(384): VFY: unable to resolve new-instance 230 (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;) in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;
04-30 17:08:30.454: DEBUG/dalvikvm(384): VFY: replacing opcode 0x22 at 0x0011
04-30 17:08:30.464: DEBUG/dalvikvm(384): VFY: dead code 0x0013-0025 in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.<init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
04-30 17:08:30.484: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.sign, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.signedGetRequest
04-30 17:08:30.505: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1062: Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;.sign (Ljava/lang/Object;)Loauth/signpost/http/HttpRequest;
04-30 17:08:30.505: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x000c
04-30 17:08:30.524: DEBUG/dalvikvm(384): VFY: dead code 0x000f-0018 in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.signedGetRequest (Ljava/lang/String;)Lcom/expertiseandroid/lib/sociallib/messages/ReadableResponse;
04-30 17:08:30.544: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.sign, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.signedPostRequest
04-30 17:08:30.544: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1062: Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;.sign (Ljava/lang/Object;)Loauth/signpost/http/HttpRequest;
04-30 17:08:30.554: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x0020
04-30 17:08:30.564: DEBUG/dalvikvm(384): VFY: dead code 0x0023-002c in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.signedPostRequest (Ljava/lang/String;Ljava/util/List;)Lcom/expertiseandroid/lib/sociallib/messages/ReadableResponse;
04-30 17:08:30.585: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.setTokenWithSecret, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.authentify
04-30 17:08:30.585: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1061: Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;.setTokenWithSecret (Ljava/lang/String;Ljava/lang/String;)V
04-30 17:08:30.595: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x000d
04-30 17:08:30.605: DEBUG/dalvikvm(384): VFY: dead code 0x0010-0012 in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.authentify (Lorg/scribe/oauth/Token;)Z
04-30 17:08:30.624: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthProvider.retrieveAccessToken, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.authorize
04-30 17:08:30.624: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1064: Loauth/signpost/commonshttp/CommonsHttpOAuthProvider;.retrieveAccessToken (Loauth/signpost/OAuthConsumer;Ljava/lang/String;)V
04-30 17:08:30.634: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x0012
04-30 17:08:30.644: DEBUG/dalvikvm(384): VFY: dead code 0x0015-002b in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.authorize (Landroid/app/Activity;)V
04-30 17:08:30.675: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.getToken, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.getAccessToken
04-30 17:08:30.675: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1059: Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;.getToken ()Ljava/lang/String;
04-30 17:08:30.685: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x0004
04-30 17:08:30.694: DEBUG/dalvikvm(384): VFY: dead code 0x0007-0015 in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.getAccessToken ()Lorg/scribe/oauth/Token;
04-30 17:08:30.724: INFO/dalvikvm(384): Could not find method oauth.signpost.commonshttp.CommonsHttpOAuthProvider.retrieveRequestToken, referenced from method com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.requestAuthorization
04-30 17:08:30.724: WARN/dalvikvm(384): VFY: unable to resolve virtual method 1065: Loauth/signpost/commonshttp/CommonsHttpOAuthProvider;.retrieveRequestToken (Loauth/signpost/OAuthConsumer;Ljava/lang/String;)Ljava/lang/String;
04-30 17:08:30.735: DEBUG/dalvikvm(384): VFY: replacing opcode 0x6e at 0x0006
04-30 17:08:30.735: DEBUG/dalvikvm(384): VFY: dead code 0x0009-0018 in Lcom/expertiseandroid/lib/sociallib/connectors/TwitterConnector;.requestAuthorization (Landroid/content/Context;)V
04-30 17:08:30.765: WARN/dalvikvm(384): VFY: unable to find class referenced in signature (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;)
04-30 17:08:30.784: DEBUG/AndroidRuntime(384): Shutting down VM
04-30 17:08:30.784: WARN/dalvikvm(384): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-30 17:08:30.825: ERROR/AndroidRuntime(384): FATAL EXCEPTION: main
04-30 17:08:30.825: ERROR/AndroidRuntime(384): java.lang.NoClassDefFoundError: oauth.signpost.commonshttp.CommonsHttpOAuthConsumer
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.<init>(TwitterConnector.java:121)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.<init>(TwitterConnector.java:113)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.expertiseandroid.lib.sociallib.connectors.SocialNetworkHelper.createTwitterConnector(SocialNetworkHelper.java:62)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.schogini.socialib2x.mainAct.onCreate(mainAct.java:35)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.os.Looper.loop(Looper.java:123)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at java.lang.reflect.Method.invoke(Method.java:507)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-30 17:08:30.825: ERROR/AndroidRuntime(384):     at dalvik.system.NativeStart.main(Native Method)
04-30 17:08:30.854: WARN/ActivityManager(60):   Force finishing activity com.schogini.socialib2x/.mainAct
04-30 17:08:31.425: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{4066a610 com.schogini.socialib2x/.mainAct}
04-30 17:08:34.014: INFO/Process(384): Sending signal. PID: 384 SIG: 9
04-30 17:08:34.094: WARN/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@405aee30
04-30 17:08:34.495: INFO/ActivityManager(60): Process com.schogini.socialib2x (pid 384) has died.
04-30 17:08:37.704: DEBUG/dalvikvm(284): GC_EXPLICIT freed 8K, 54% free 2543K/5511K, external 716K/1038K, paused 91ms
04-30 17:08:42.408: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{4066a610 com.schogini.socialib2x/.mainAct}
04-30 17:08:42.855: DEBUG/dalvikvm(297): GC_EXPLICIT freed 321K, 54% free 2539K/5511K, external 716K/1038K, paused 186ms
04-30 17:08:47.844: DEBUG/dalvikvm(311): GC_EXPLICIT freed 476K, 55% free 2592K/5703K, external 716K/1038K, paused 103ms

在此先感谢...

Thanks in Advance...

推荐答案

似乎缺少了OAuth的库。有没有可能是你需要包括支持OAuth路标

It seems that is missing an oauth library. Is it possible that you need to include oauth-signpost?

这篇关于示例项目/教程演示sociallibs在Android的不同特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:59