gpt4 book ai didi

android - Facebook 喜欢按钮在 Android 应用程序中不起作用

转载 作者:行者123 更新时间:2023-11-30 02:07:15 25 4
gpt4 key购买 nike

我已经按照一些教程学习如何将 facebook 与 android 应用程序一起使用。我设法实现了有效的“登录”按钮和“共享”按钮,但是我无法使按钮正常工作。在我按下它之后,我得到这个问题图像出现了一秒钟然后它消失了:

enter image description here

这是我的应用程序代码(其中包含 fragment 的简单 Activity ):

public class FacebookFragment extends Fragment {
private View rootView;
private TextView simpleTextView;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//PODSTAWOWE RZECZY
FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); //facebook
callbackManager = CallbackManager.Factory.create();
registerCallback();

//JAKIEŚ TOKENY I INNE TRACKERY DO UPDATÓW
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
Toast.makeText(getActivity().getApplicationContext(), "currentAccessTokenChanged", Toast.LENGTH_LONG).show();
simpleTextView.setText("current access token changed");
}
};
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
// App code
if (currentProfile != null) {
((TextView) rootView.findViewById(R.id.textView)).setText("Welcome " + currentProfile.getName());
} else {
Toast.makeText(getActivity().getApplicationContext(), "Profil null", Toast.LENGTH_LONG).show();
}
}
};
//ZACZYNAMY ŚLEDZIĆ
profileTracker.startTracking();
accessTokenTracker.startTracking();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_facebook, container, false);

//SPRAWDZAMY CZY ZALOGOWANY JEST UZYTKOWNIK I ROBIMY SET-UP PROGRAMU
simpleTextView = (TextView) rootView.findViewById(R.id.textView);
checkIfLogged();
setFacebookLoginButton();
setFacebookLikeButton();
setFacebookShareButton();

// Inflate the layout for this fragment
return rootView;
}

@Override
public void onStop() {
super.onStop();
//STOPUJEMY TRACKING
accessTokenTracker.stopTracking();
profileTracker.stopTracking();
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

}

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


//========================= CUSTOM METHODS ========================================
private void checkIfLogged(){
Profile profile = Profile.getCurrentProfile();
if (AccessToken.getCurrentAccessToken() != null) {
simpleTextView.setText("Welcome " + profile.getName());
} else {
Toast.makeText(getActivity().getApplicationContext(), "not logged in", Toast.LENGTH_LONG).show();
}
}

private void setFacebookLoginButton(){
LoginButton facebookButton = (LoginButton) rootView.findViewById(R.id.login_button);
facebookButton.setFragment(this);
}
private void registerCallback(){
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
}
@Override
public void onCancel() {
Toast.makeText(getActivity().getApplicationContext(), "too bad you didn't log in...", Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(getActivity().getApplicationContext(), "that's that error shit...", Toast.LENGTH_LONG).show();
}
});
}
private void setFacebookLikeButton(){
LikeView likeView = (LikeView) rootView.findViewById(R.id.like_button);
likeView.setLikeViewStyle(LikeView.Style.STANDARD);
likeView.setFragment(this);
likeView.setOnErrorListener(new LikeView.OnErrorListener() {
@Override
public void onError(FacebookException e) {
Toast.makeText(getActivity().getApplicationContext(), "masz chuja nie lajka...", Toast.LENGTH_LONG).show();
}
});
likeView.setObjectIdAndType("https://www.facebook.com/FacebookDevelopers", LikeView.ObjectType.PAGE);
}
private void setFacebookShareButton(){
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://joemonster.org"))
.setImageUrl(Uri.parse("http://joemonster.org/i/2015/05/pasazer.jpg")).
setContentDescription("Prawdopodobnie najlepsza strona we wszechświecie!")
.setContentTitle("Joe Monster")
.build();

ShareButton shareButton = (ShareButton)rootView.findViewById(R.id.share_button);
shareButton.setFragment(this);
shareButton.setShareContent(content);
}
}

其他有关行为:

  • 如果我使用“共享”按钮登录,那么我的“登录”按钮不会变为显示“注销”。如果我然后单击“登录”按钮并取消它。我将不得不使用“分享”或“喜欢”按钮再次“登录”。
  • 如果我使用“登录”按钮登录,然后在点赞按钮下方我会看到该网站获得的点赞数。

我的虚拟设备上没有安装 Facebook 应用程序。

最佳答案

“赞”按钮的使用需要应用程序批准,因此在开发期间,只有在您的应用程序中具有管理员/开发人员/测试人员角色的用户才能访问它。一旦获得批准,任何用户都可以使用该功能。

关于android - Facebook 喜欢按钮在 Android 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30510102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com