eclipse Session.StatusCallback 无法解析为类型 - Facebook API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16926123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Session.StatusCallback cannot be resolved to a type - Facebook API
提问by Rucha Heda
I followed the login authentication tutorial on Facebook and have copied the following code into my android application
我遵循了 Facebook 上的登录身份验证教程,并将以下代码复制到我的 android 应用程序中
private Session.StatusCallback callback =
new Session.StatusCallback()
{
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
However, it is giving me the following errors:
但是,它给了我以下错误:
Session.StatusCallback cannot be resolved to a type
Which is leading to the following errors:
这导致以下错误:
callback cannot be resolved to a variable
There's also other places where Facebook API calls are made that are giving me errors, but it's not in all the Facebook API calls. Another place I'm getting an error is the following:
还有其他地方进行了 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();
where it does not recognize Request.GraphUserCallback, and then executeAsync(). I get the following errors:
它不识别Request.GraphUserCallback,然后执行Async()。我收到以下错误:
Request.GraphUserCallback cannot be resolved to a type
The method executeAsync() is undefined for the type DownloadManager.Request
Does anyone have any advice as to how to fix this?
有没有人对如何解决这个问题有任何建议?
Thank you for your help in advance!!
提前谢谢你的帮助!!
回答by user2688443
I had the same problem as your first one, and I solved it by removing
我和你的第一个遇到了同样的问题,我通过删除来解决它
import android.service.textservice.SpellCheckerService.Session;
and adding
并添加
import com.facebook.Session;
回答by wallacer
I had a similar issue, and the problem was that I had these two imports in the file
我有一个类似的问题,问题是我在文件中有这两个导入
import android.app.DownloadManager.Request;
import android.service.textservice.SpellCheckerService.Session;
And those Request and Session modules were overriding
那些请求和会话模块被覆盖
com.facebook.Session
com.facebook.Request
I actually just removed the two android imports and everything worked nicely. They didn't seem to be used, but eclipse added them in for some strange reason.
我实际上只是删除了两个 android 导入,一切都运行良好。它们似乎没有被使用,但是 eclipse 出于某种奇怪的原因将它们添加了进来。
Judging by your output
看你的输出
The method executeAsync() is undefined for the type DownloadManager.Request
I'd say it sounds like you have the same imports happening somewhere and they're overriding the facebook imports.
我会说听起来你在某处发生了相同的导入,并且它们覆盖了 facebook 导入。
回答by jpmastermind
Got this issue when having both Request and Session classes from Volley framework already imported. Try using the class with the package name for Session and Request, it worked for me. See below's code.
当已从 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);
}
};
回答by Luser_k
For your first problem, which import do you use ? I use this for the Callback:
对于您的第一个问题,您使用哪个导入?我将它用于回调:
import com.facebook.Session.StatusCallback;
Which Facebook SDK are you using ? The newest one ? I am using latest sdk 4.01 butin this sdk is not support this pakage
您使用的是哪个 Facebook SDK?最新的?我使用的是最新的 sdk 4.01 但这个 sdk 不支持这个包
回答by CoolMind
I had a message: "Cannot resolve symbol Session". So, the problem was in non-plugged library "facebook". I resolved it so. 1. Open Project Structure (File > Project Structure). 2. Select Modules on the left pane. 3. Choose your project name. 4. Click Dependencies tab. 5. Click on the plus sign in the bottom. Select "Module dependency" and click "facebook". 6. Press OK, then OK.
我收到一条消息:“无法解析符号会话”。因此,问题出在非插入式库“facebook”中。我是这样解决的。1. 打开项目结构(文件 > 项目结构)。2. 在左侧窗格中选择模块。3. 选择您的项目名称。4. 单击依赖项选项卡。5. 单击底部的加号。选择“模块依赖”并点击“facebook”。6. 按 OK,然后按 OK。
回答by Vishal Singh
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);
}
}
Reference link for facebook sdk where You can download and use it. its work for me http://www.filedropper.com/facebooksdk
facebook sdk 的参考链接,您可以在其中下载和使用它。它对我 有用 http://www.filedropper.com/facebooksdk
回答by Shun Y.
Just delete the FB SDK and re-download it. Your SDK is probably corrupted by others who pushed to git.
只需删除FB SDK并重新下载即可。您的 SDK 可能已被推送到 git 的其他人损坏。