我想从Android应用程序访问我的Facebook令牌。我正在尝试此代码,但它无法正常工作。我该怎么办?我有appid和appsecret:
代码:
public class MainActivity extends Activity {
FacebookClient fbs;
Facebook fb;
String appid;
String appsecret;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appid="";
appsecret="";
AccessToken accessToken= fbs.obtainAppAccessToken(appid,appsecret);
AccessToken accessToken1 = new DefaultFacebookClient().obtainAppAccessToken(appid,appsecret);
String token=accessToken1.getAccessToken();
TextView txtview = (TextView)findViewById(R.id.textview1);
txtview.setText(token);
}
错误
06-15 12:06:37.086: I/dalvikvm(2113): Could not find method com.restfb.FacebookClient.obtainAppAccessToken, referenced from method com.example.nbbnvntfg.MainActivity.onCreate
06-15 12:06:37.166: W/dalvikvm(2113): VFY: unable to resolve interface method 8434: Lcom/restfb/FacebookClient;.obtainAppAccessToken (Ljava/lang/String;Ljava/lang/String;)Lcom/restfb/FacebookClient$AccessToken;
06-15 12:06:37.166: D/dalvikvm(2113): VFY: replacing opcode 0x72 at 0x0017
06-15 12:06:37.236: D/dalvikvm(2113): DexOpt: unable to opt direct call 0x20ef at 0x1d in Lcom/example/nbbnvntfg/MainActivity;.onCreate
06-15 12:06:38.386: D/AndroidRuntime(2113): Shutting down VM
06-15 12:06:38.386: W/dalvikvm(2113): threadid=1: thread exiting with uncaught exception (group=0xb3aa7ba8)
06-15 12:06:38.406: E/AndroidRuntime(2113): FATAL EXCEPTION: main
06-15 12:06:38.406: E/AndroidRuntime(2113): Process: com.example.nbbnvntfg, PID: 2113
06-15 12:06:38.406: E/AndroidRuntime(2113): java.lang.NoSuchMethodError: com.restfb.FacebookClient.obtainAppAccessToken
06-15 12:06:38.406: E/AndroidRuntime(2113): at com.example.nbbnvntfg.MainActivity.onCreate(MainActivity.java:28)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.Activity.performCreate(Activity.java:5231)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.os.Handler.dispatchMessage(Handler.java:102)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.os.Looper.loop(Looper.java:136)
06-15 12:06:38.406: E/AndroidRuntime(2113): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-15 12:06:38.406: E/AndroidRuntime(2113): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 12:06:38.406: E/AndroidRuntime(2113): at java.lang.reflect.Method.invoke(Method.java:515)
06-15 12:06:38.406: E/AndroidRuntime(2113): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-15 12:06:38.406: E/AndroidRuntime(2113): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-15 12:06:38.406: E/AndroidRuntime(2113): at dalvik.system.NativeStart.main(Native Method)
06-15 12:06:45.316: I/Process(2113): Sending signal. PID: 2113 SIG: 9
如何解决它请帮助我......
答案 0 :(得分:0)
Auth令牌由Session自sdk 3.0自动管理。在任何情况下都不需要访问它。