我按照Facebook上的登录身份验证教程,将以下代码复制到我的Android应用程序
private Session.StatusCallback callback =
new Session.StatusCallback()
{
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
然而,它给了我以下错误:
Session.StatusCallback cannot be resolved to a type
导致以下错误:
callback cannot be resolved to a variable
还有其他地方Facebook API调用会给我带来错误,但它并不是所有的Facebook API调用。另一个我收到错误的地方如下:
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
if (user != null) {
// Set the id for the ProfilePictureView
// view that in turn displays the profile picture.
Log.d("MainActivity", "onComplete() User logged in");
parent.owner = MainKickback.userConnection.add(new User(user.getId()));
EventFragment e = (EventFragment) fragments[UPCOMING_EVENTS];
e.populateEvents();
}
}
if (response.getError() != null) {
// Handle errors, will do so later.
}
}
});
request.executeAsync();
它不识别Request.GraphUserCallback,然后执行executeAsync()。我收到以下错误:
Request.GraphUserCallback cannot be resolved to a type
The method executeAsync() is undefined for the type DownloadManager.Request
有没有人对如何解决这个问题有任何建议?
提前感谢您的帮助!!
答案 0 :(得分:17)
我和你的第一个问题一样,我通过删除
解决了这个问题import android.service.textservice.SpellCheckerService.Session;
并添加
import com.facebook.Session;
答案 1 :(得分:3)
我有一个类似的问题,问题是我在文件中有这两个导入
import android.app.DownloadManager.Request;
import android.service.textservice.SpellCheckerService.Session;
那些请求和会话模块覆盖
com.facebook.Session
com.facebook.Request
我实际上刚删除了两个android导入,一切运行良好。它们似乎没有被使用,但是eclipse因为一些奇怪的原因加入了它们。
根据你的输出判断
The method executeAsync() is undefined for the type DownloadManager.Request
我说这听起来好像你在某处发生了相同的进口,而且它们正在压倒facebook的进口。
答案 2 :(得分:2)
在已经导入Volley框架的Request和Session类时遇到此问题。尝试使用包含Session和Request包名的类,它对我有用。请参阅下面的代码。
private com.facebook.Session.StatusCallback callback =
new com.facebook.Session.StatusCallback()
{
@Override
public void call(com.facebook.Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
答案 3 :(得分:1)
对于您的第一个问题,您使用哪种导入?我将它用于回调:
import com.facebook.Session.StatusCallback;
您使用的是哪个Facebook SDK?最新的? 我正在使用最新的sdk 4.01但是这个sdk不支持这个pakage
答案 4 :(得分:0)
我收到一条消息:“无法解析符号会话”。所以,问题出在非插件库“facebook”。我解决了这个问题。 1.打开项目结构(文件>项目结构)。 2.在左窗格中选择“模块”。 3.选择您的项目名称。 4.单击“依赖关系”选项卡。 5.单击底部的加号。选择“模块依赖关系”,然后单击“Facebook”。 6.按“确定”,然后按“确定”。
答案 5 :(得分:0)
package com.vishal.example;
import com.facebook.Response;
import com.facebook.UiLifecycleHelper;
import com.facebook.Response;
import com.facebook.UiLifecycleHelper;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;
import com.facebook.Request;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity
{
private UiLifecycleHelper uiHelper;
private View otherView;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set View that should be visible after log-in invisible initially
otherView = (View) findViewById(R.id.other_views);
otherView.setVisibility(View.GONE);
// To maintain FB Login session
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
}
// Called when session changes
private Session.StatusCallback callback = new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
onSessionStateChange(session, state, exception);
}
};
// When session is changed, this method is called from callback method
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
final TextView name = (TextView) findViewById(R.id.name);
final TextView gender = (TextView) findViewById(R.id.gender);
final TextView location = (TextView) findViewById(R.id.location);
// When Session is successfully opened (User logged-in)
if (state.isOpened())
{
Log.i(TAG, "Logged in...");
// make request to the /me API to get Graph user
Request.newMeRequest(session, new Request.GraphUserCallback()
{
// callback after Graph API response with user
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
// Set view visibility to true
otherView.setVisibility(View.VISIBLE);
// Set User name
name.setText("Hello " + user.getName());
// Set Gender
gender.setText("Your Gender: " + user.getProperty("gender").toString());
location.setText("Your Current Location: " + user.getLocation().getProperty("name").toString());
}
}
}).executeAsync();
}
else if(state.isClosed())
{
Log.i(TAG, "Logged out...");
otherView.setVisibility(View.GONE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "OnActivityResult...");
}
@Override
public void onResume()
{
super.onResume();
uiHelper.onResume();
}
@Override
public void onPause()
{
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy()
{
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
}
facebook sdk的参考链接,您可以下载并使用它。它为我工作 http://www.filedropper.com/facebooksdk
答案 6 :(得分:-1)
只需删除FB SDK并重新下载即可。 您的SDK可能会被推送到git的其他人破坏。