GVKun编程网logo

Facebook 在打开对话时自动发送消息(facebook设置自动消息回复)

10

在本文中,我们将详细介绍Facebook在打开对话时自动发送消息的各个方面,并为您提供关于facebook设置自动消息回复的相关解答,同时,我们也将为您带来关于#import"facebookSDK/

在本文中,我们将详细介绍Facebook 在打开对话时自动发送消息的各个方面,并为您提供关于facebook设置自动消息回复的相关解答,同时,我们也将为您带来关于#import "facebookSDK/FacebookSDK.h file not found"、android – com.facebook.FacebookException:尝试使用未打开的Session、android – Facebook SDK 3.0 – 获取Facebook用户名和访问令牌、android – Facebook活动未在facebook-sdk 4.4.0中正确加载的有用知识。

本文目录一览:

Facebook 在打开对话时自动发送消息(facebook设置自动消息回复)

Facebook 在打开对话时自动发送消息(facebook设置自动消息回复)

您可以使用 API 设置问候文本,甚至包括用户名:

https://developers.facebook.com/docs/messenger-platform/discovery/welcome-screen/

#import <FacebookSDK/FacebookSDK.h>

#import "facebookSDK/FacebookSDK.h file not found"

第一种可能: 从window下上传到mac 下 facebook sdk出错!【这个是系统的错误,只能从其他地方拷贝 FacebookSDK.framework 文件夹 就ok】,下图是正常状态,【不正常的状态下,这几个文件直接是物理文件了】

第二种可能 ,设置读取路径错误


在mac下 project下找到build setting ,再找 searchPath,点击Framework search paths 设置路径即可

"$(SRCROOT)/xxx/xxx/FacebookSDK.framework"

android – com.facebook.FacebookException:尝试使用未打开的Session

android – com.facebook.FacebookException:尝试使用未打开的Session

我整合了facebook分享,它在过去几天工作得很好,但是今天在问这个问题之前的2个小时我正面临着这个问题.

我正在使用此代码登录:

  Session.openActiveSession(this, true, new Session.StatusCallback() {

// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
  if (state.isOpened()) {

    // make request to the /me API
    Request.newMeRequest(session, new Request.GraphUserCallback() {

      // callback after Graph API response with user object
      @Override
      public void onCompleted(GraphUser user, Response response) {
        if (user != null) {

          Toast.makeText(ImagePagerActivity.this, user.getName()+" Logged In...", Toast.LENGTH_LONG).show();
        }
      }
    }).executeAsync();
  }
}
});
publishFeedDialog();

问题是if()条件总是假的,我也使用session.isOpened()也返回false,我很困惑为什么会发生这种情况.

我已经在清单中声明了INTERNET,ACCESSNETWORKSTATE,权限

 <application>
 ..........
 ..........
 <Meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
 </application>

请帮忙…

编辑

这是我实现的代码,你可以看到onCreateOptionsMenu,onoptionsItemSelected,onActivityResult,publishFeedDialog

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar_share_menu, menu);
        MenuItem item = menu.findItem(R.id.menu_item_share1);


        return true;
    }
@Override

public boolean      onoptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share1: // facebook item selected
Toast.makeText(this, "Menu Item 1 selected", Toast.LENGTH_SHORT).show();
//start Facebook Login


Session.openActiveSession(this, true, new Session.StatusCallback() {

// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
  if (state.isOpened()) {

    // make request to the /me API
    Request.newMeRequest(session, new Request.GraphUserCallback() {

      // callback after Graph API response with user object
      @Override
      public void onCompleted(GraphUser user, Response response) {
        if (user != null) {

          Toast.makeText(ImagePagerActivity.this, user.getName()+" Logged In...", Toast.LENGTH_LONG).show();
        }
      }
    }).executeAsync();
  }
}
});
publishFeedDialog();

}
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
        @Override
        public void one rror(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }
    });

}
@Override
protected void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putInt(STATE_POSITION, pager.getCurrentItem());
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

private void publishFeedDialog() {

    Log.v("pos",""+pos);
    Bundle params = new Bundle();
    params.putString("name", ItemListApplication.names.get(pos).getItem());
    params.putString("caption", "Irrational beliefs");
    params.putString("description",ItemListApplication.names.get(pos).getDesc() );
    params.putString("link", "https://www.facebook.com/vivek.warde.3?ref=tn_tnmn");

    if(pos==0) params.putString("picture","http://i.imgur.com/lOIUcW2.jpg");
    else params.putString("picture",imageUrls[pos]);
    WebDialog FeedDialog = (
        new WebDialog.FeedDialogBuilder(this,
            Session.getActiveSession(),
            params))
        .setonCompleteListener(new OnCompleteListener() {

            @Override
            public void onComplete(Bundle values,
                FacebookException error) {
                if (error == null) {
                    // When the story is posted, echo the success
                    // and the post Id.
                    final String postId = values.getString("post_id");
                    if (postId != null) {
                        Toast.makeText(ImagePagerActivity.this,
                            "Posted story, id: "+postId,
                            Toast.LENGTH_SHORT).show();
                    } else {
                        // User clicked the Cancel button
                        Toast.makeText(ImagePagerActivity.this, 
                            "Publish cancelled", 
                            Toast.LENGTH_SHORT).show();
                    }
                } else if (error instanceof FacebookOperationCanceledException) {
                    // User clicked the "x" button
                    Toast.makeText(ImagePagerActivity.this, 
                        "Publish cancelled", 
                        Toast.LENGTH_SHORT).show();
                } else {
                    // Generic, ex: network error
                    Toast.makeText(ImagePagerActivity.this, 
                        "Error posting story", 
                        Toast.LENGTH_SHORT).show();
                }
            }

        })
        .build();
    FeedDialog.show();
}

解决方法:

处理这个问题可能有很多原因.你应该检查一下:

我正在使用此代码通过Facebook登录:

class MyFragment extends Fragment {
   //... some code

   SessionStatusCallback statusCallback = new SessionStatusCallback();

   public void login() {
       Session session = Session.getActiveSession();
       if (!session.isOpened() && !session.isClosed()) {
           session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
       } else {
           Session.openActiveSession(getActivity(), this, true, statusCallback);
       }
   }

   private class SessionStatusCallback implements Session.StatusCallback {
       @Override
       public void call(Session session, SessionState state, Exception exception) {
           if (exception != null) {
               handleException(exception);
           }
           if (state.isOpened()) {
               afterLogin();
           } else if (state.isClosed()) {
               afterlogout();
           }
        }
    }

}

如果未打开会话,则应将其打开以供阅读(如果需要,则打开publish).

检查AndroidManifest文件中的元数据标记,是否有正确的应用程序ID?

经常发生错误不在Android应用程序内,但在Facebook应用程序设置.在facebook应用程序的设置页面中应该是正确的软件包名称,您应该为您的应用程序添加密钥哈希值(每种版本类型都不同,在大多数情况下是调试和发布).

要获取哈希键,您可以运行脚本

keytool -exportcert -alias YOUR_ALIAS -keystore PATH_TO_KEYSTORE_FILE | openssl sha1 -binary | openssl base64

或者你可以在代码中获取它:

PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("YOUR_APP_PACKAGE", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String keyhash = new String(Base64.encode(md.digest(), 0));
        //string something is what you should paste as key hash
        Log.e("hash key", keyhash);
    }
} catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());
} 

在Facebook应用程序的设置页面中状态&审核标签,您应该公开app.或者,如果您仍然不想将其公开,则应为可以使用您的Android应用程序的所有用户添加角色(在“角色”选项卡中).

此外,如果它没有帮助,尝试调试方法
public void call(会话会话,SessionState状态,异常异常)
通常有正常的消息,为什么授权不成功

android – Facebook SDK 3.0 – 获取Facebook用户名和访问令牌

android – Facebook SDK 3.0 – 获取Facebook用户名和访问令牌

我搜索了过去两天,并没有成功找到从Facebook SDK 3.0 – 本地登录获取用户标识和访问令牌的方法.

我正在跟随facebook本地登录 – http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/

我使用Session.getAccesstoken获取访问令牌,我得到一些访问令牌,但是这是无效的.实际程序是什么?我做错了吗

如何使用Facebook SDK 3.0在Native登录中获取UserId

解决方法

用户名:
final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        // If the session is open,make an API call to get user data
        // and define a new callback to handle the response
        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) {
                        user_ID = user.getId();//user id
                        profileName = user.getName();//user's profile name
                        userNameView.setText(user.getName());
                    }   
                }   
            }   
        }); 
        Request.executeBatchAsync(request);
    }

user_ID& profileName是字符串.

对于accesstoken:

String token = session.getAccesstoken();

EDITED:(13/1/2014)

对于用户电子邮件(我没有通过在设备或模拟器上运行来检查此代码):

这些只是我的意见,或者你可以称之为建议

setReadPermissions(Arrays.asList("email",...other permission...));
//by analyzing the links bellow,i think you can set the permission in loginbutton as:
loginButton.setReadPermissions(Arrays.asList("email",...other permission...));
user.asMap().get("email");

更多信息请看:
link1,link2,link3,link4,

android – Facebook活动未在facebook-sdk 4.4.0中正确加载

android – Facebook活动未在facebook-sdk 4.4.0中正确加载

我想在我的Android应用程序中集成Facebook登录.我使用的是Facebook-sdk-4.4.0.使用LoginManager类方法.但是我在运行以下代码时面临问题 –

FacebookSdk.sdkInitialize(getApplicationContext());    
callbackmanager = CallbackManager.Factory.create();

// Set permissions
LoginManager.getInstance().logInWithReadPermissions((Activity)getContext(), Arrays.asList("email", "public_profile"));

LoginManager.getInstance().registerCallback(callbackmanager,
        new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccesstoken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject userInfo, GraphResponse graphResponse) {
                                try {
                                    FacebookClientController.setUserId(userInfo.optString(ID));
                                    FacebookClientController.setdisplayName(userInfo.optString(NAME));
                                    FacebookClientController.setEmailAddress(userInfo.optString(EMAIL));
                                    JSONObject picJson = userInfo.getJSONObject(PICTURE).getJSONObject("data");
                                    FacebookClientController.setProfilePicUrl(picJson.optString("url"));
                                    Log.d(LOGTAG, "\nUsername :" + FacebookClientController.getdisplayName());
                                    Log.d(LOGTAG, "\nEmail :" + FacebookClientController.getEmailAddress());
                                    Log.d(LOGTAG, "\nUserId :" + FacebookClientController.getUserId());
                                    Log.d(LOGTAG, "\nProfilePicUrl :" + FacebookClientController.getProfilePicUrl());
                                } catch (JSONException e) {
                                    Log.d(LOGTAG, "Json Error");
                                }
                            }
                        }
                );
                Bundle parameters = new Bundle();
                parameters.putString(FIELDS, FB_REQUEST_FIELDS);
                request.setParameters(parameters);
                GraphRequest.executeBatchAsync(request);

                Toast.makeText(getContext(), "Login successful" + loginResult.toString(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancel() {
                Log.d(LOGTAG, "On cancel");
            }

            @Override
            public void one rror(FacebookException error) {
                Log.d(LOGTAG, error.toString());
            }
        });
}

我正在我的应用程序中的左侧屏幕而不是正确的屏幕,这应该运行上面的代码.谁能告诉我哪里可以出问题?
logcat的:

——— beginning of /dev/log/main

I/AppHost.Android(10873): Registered listener for handling
onActivityResult: com.example.office.docsui.common.SignInController$5

——— beginning of /dev/log/system

I/ActivityManager( 449): START u0 {act=NATIVE_WITH_FALLBACK
cmp=com.example.office.powerworld/com.facebook.FacebookActivity (has
extras)} from pid 10873

I/TelemetryLifeCycleState(10873): Activity Pause Start.
Activity:1099625720,PPTActivity, AppState=3

I/ActivityManager( 449): START u0 {act=NATIVE_WITH_FALLBACK
cmp=com.example.office.powerworld/com.facebook.FacebookActivity (has
extras)} from pid 10873

I/TelemetryLifeCycleState(10873): Activity Pause End.
Activity:1099625720,PPTActivity, AppState=2

I/TelemetryLifeCycleState(10873): Activity Created.
Activity:1107534680,com.facebook.FacebookActivity

I/AppHost.Android(10873): onActivityStarted,
foregroundActivityCount=1, mEventsEnabled= true, mResumeEnabled=false

I/AppHost.Android(10873): this is not an office
activity::com.facebook.FacebookActivity

I/TelemetryLifeCycleState(10873): Activity Resume Start.
Activity:1107534680,com.facebook.FacebookActivity, AppState=2

I/TelemetryLifeCycleState(10873): Activity Resume End.
Activity:1107534680,com.facebook.FacebookActivity, AppState=3,
suspensionTime=54215

I/TelemetryLifeCycleState(10873): Activity Pause Start.
Activity:1107534680,com.facebook.FacebookActivity, AppState=3

I/TelemetryLifeCycleState(10873): Activity Pause End.
Activity:1107534680,com.facebook.FacebookActivity, AppState=2

I/TelemetryLifeCycleState(10873): Activity Created.
Activity:1107673504,com.facebook.FacebookActivity

D/dalvikvm(10873): GC_FOR_ALLOC freed 2064K, 20% free 8974K/11096K,
paused 27ms, total 30ms

I/AppHost.Android(10873): onActivityStarted,
foregroundActivityCount=1, mEventsEnabled= true, mResumeEnabled=false

I/AppHost.Android(10873): this is not an office
activity::com.facebook.FacebookActivity

I/TelemetryLifeCycleState(10873): Activity Resume Start.
Activity:1107673504,com.facebook.FacebookActivity, AppState=2

I/TelemetryLifeCycleState(10873): Activity Resume End.
Activity:1107673504,com.facebook.FacebookActivity, AppState=3,
suspensionTime=54303

D/mali_winsys(10873): new_window_surface returns 0x3000

D/mali_winsys(10873): new_window_surface returns 0x3000

D/mali_winsys(10873): new_window_surface returns 0x3000

D/mali_winsys(10873): new_window_surface returns 0x3000

I/Keyboard.Facilitator( 614): onFinishinput()

I/ActivityManager( 449): displayed
com.example.office.powerworld/com.facebook.FacebookActivity: +346ms

I/ActivityManager( 449): displayed
com.example.office.powerworld/com.facebook.FacebookActivity: +346ms

D/mali_winsys(10873): new_window_surface returns 0x3000

D/mali_winsys(10873): new_window_surface returns 0x3000

I/K2_ULS (10873): 07/21/2015 17:24:38.293 PPTDROID
(0x2a79) 0x40066154 Example powerworld AppHost
PLM a2k0b Medium PauseHandlerActivityLifecycleCallbacks:onActivitySaveInstanceState
called

I/Keyboard.Facilitator( 614): onFinishinput()

W/InputMethodManagerService( 449): Window already focused, ignoring
focus gain of:
com.android.internal.view.IInputMethodClient$Stub$Proxy@4227f090
attribute=android.view.inputmethod.EditorInfo@423ba3a8, token =
android.os.BinderProxy@41f633d8

解决方法:

试试这个吧

LoginButton loginButton;
CallbackManager callbackManager;

FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();

loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("public_profile", "user_friends", "email"));

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            Profile profile = Profile.getCurrentProfile();
            profile.getProfilePictureUri(315, 315);
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccesstoken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            Log.v("LoginActivity", response.toString());
                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void one rror(FacebookException e) {
            e.printstacktrace();
        }
    });

并覆盖以下方法

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);         
}

并在清单中定义它

<activity
        android:name="com.facebook.FacebookActivity"            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

我们今天的关于Facebook 在打开对话时自动发送消息facebook设置自动消息回复的分享已经告一段落,感谢您的关注,如果您想了解更多关于#import "facebookSDK/FacebookSDK.h file not found"、android – com.facebook.FacebookException:尝试使用未打开的Session、android – Facebook SDK 3.0 – 获取Facebook用户名和访问令牌、android – Facebook活动未在facebook-sdk 4.4.0中正确加载的相关信息,请在本站查询。

本文标签: