gpt4 book ai didi

Android Facebook API 授权/记住它的一面,但不是我的?

转载 作者:行者123 更新时间:2023-11-29 18:22:39 26 4
gpt4 key购买 nike

在我的代码中,我可以让 Facebook 出现,显示请求的权限并授权,每次我返回时它会记住我是谁。

在我的应用程序本身中,虽然它似乎无法识别它已登录,但对 Authorize 的调用永远不会通过 DialogListener 接口(interface)返回。我的应用程序适配器的代码有些不完整。

package com.metalrain.ca.newschoolshooter_full;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import Hammer.App.MyLibs.APPSTATICS;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;

public class FacebookIntegrator implements DialogListener{



public static final String APP_ID = "176680882361390";

private final Facebook mFacebook;
//private final AsyncFacebookRunner mAsyncRunnoner;

Context ctx;
String[] Permissions = new String[] {"publish_stream", "read_stream", "offline_access"};

FacebookIntegrator(final Context ctx) {
this.ctx = ctx;
this.mFacebook = new Facebook(FacebookIntegrator.APP_ID);
//this.mAsyncRunner = new AsyncFacebookRunner(this.mFacebook);
}

public void SubmitScore() {
Log.e("MetalRain", "Started SubmitScore"+mFacebook.getAccessToken());
//I use the class from the login button to do this
//final LoginButton lb = new LoginButton(this.ctx);

if (mFacebook.isSessionValid()) {
Log.i("MetalRain", "There is a valid facebook sessi");
Bundle b = new Bundle();
try {
mFacebook.request("/me/feed", b, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b.putString("status", "This is a test: name");

} else {
Log.i("MetalRain","Authorizing facebook");
mFacebook.authorize((Activity) this.ctx,this.Permissions,
this);
}
Log.e("MetalRain", "Finished SubmitScore");
}

public void onComplete(Bundle values) {
if (!values.containsKey("post_id"))
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", "this is a test");// the message to post to the wall
mFacebook.dialog(APPSTATICS.CTX, "stream.publish", parameters, this);// "stream.publish" is an API call
}
catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}
}

Log.e("MetalRain", "On Complete");
}

public void onFacebookError(FacebookError error) {
Log.e("MetalRain","fbFAILURE "+error.getMessage());
}

public void onError(DialogError error) {
Log.e("MetalRain","FAILURE "+error.getMessage());
}

public void onCancel() {
Log.e("MetalRain","CANCELED");
}
}

返回后我没有看到任何错误或任何日志消息。它只是返回我的 Activity 并表现得好像什么都没发生。

最佳答案

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
fbi.mFacebook.authorizeCallback(requestCode, resultCode, data);
}

这是最新版本所要求的,因为它是一个完整的 Activity ,而不是某种形式的远程对话。一旦我添加了它,它就全部工作了(添加到我的 Activity,而不是上面的代码,fbi 是 FacebookIntegrator,上面链接的类)。

关于Android Facebook API 授权/记住它的一面,但不是我的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4481685/

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