4

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

これを修正する方法について誰かアドバイスはありますか?

よろしくお願いします!

4

7 に答える 7

17

最初の問題と同じ問題がありましたが、削除して解決しました

import android.service.textservice.SpellCheckerService.Session;

と追加

import com.facebook.Session;
于 2013-08-16T06:56:26.267 に答える
3

同様の問題がありましたが、問題はファイルにこれら2つのインポートがあることでした

import android.app.DownloadManager.Request;
import android.service.textservice.SpellCheckerService.Session;

これらの Request および Session モジュールはオーバーライドされていました

com.facebook.Session
com.facebook.Request

私は実際に2つのAndroidインポートを削除しただけで、すべてうまくいきました。それらは使用されていないようでしたが、何らかの奇妙な理由でEclipseがそれらを追加しました。

あなたの出力から判断する

The method executeAsync() is undefined for the type DownloadManager.Request

同じインポートがどこかで発生していて、Facebook のインポートをオーバーライドしているように聞こえると思います。

于 2013-08-02T05:45:33.217 に答える
2

Volley フレームワークの Request クラスと Session クラスの両方が既にインポートされている場合に、この問題が発生しました。セッションとリクエストのパッケージ名を持つクラスを使用してみてください。うまくいきました。以下のコードを参照してください。

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);
    }
};
于 2014-03-19T08:11:25.367 に答える
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

于 2016-03-21T09:54:51.233 に答える
0

「シンボル セッションを解決できません」というメッセージが表示されました。というわけで、プラグインされていないライブラリ「facebook」に問題がありました。そう解決しました。1. プロジェクト構造を開きます (ファイル > プロジェクト構造)。2. 左ペインでモジュールを選択します。3. プロジェクト名を選択します。4. [依存関係] タブをクリックします。5. 下部のプラス記号をクリックします。「モジュール依存関係」を選択し、「facebook」をクリック。6. [OK] を押してから [OK] を押します。

于 2014-09-01T06:44:39.653 に答える