Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Facebook整合不是';t工作不正常_Android_Facebook Graph Api - Fatal编程技术网

Android Facebook整合不是';t工作不正常

Android Facebook整合不是';t工作不正常,android,facebook-graph-api,Android,Facebook Graph Api,我已经在我的facebook集成演示应用程序中集成了facebook sdk。当我点击按钮时,会出现一个片段,我可以登录,但它不会返回任何值。我没有任何关于logcat的信息 这是我的代码: package com.example.manishnegi.facebooklogin; public class MainActivity extends Activity { LoginButton btn; CallbackManager callbackManager; @Override p

我已经在我的facebook集成演示应用程序中集成了facebook sdk。当我点击按钮时,会出现一个片段,我可以登录,但它不会返回任何值。我没有任何关于logcat的信息

这是我的代码:

package com.example.manishnegi.facebooklogin;

public class MainActivity extends Activity {
LoginButton btn;
CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);
    callbackManager=CallbackManager.Factory.create();

    btn=(LoginButton)findViewById(R.id.login_button);
    btn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {


        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();

            AccessToken accessToken=loginResult.getAccessToken();
           GraphRequest request = GraphRequest.newMeRequest(
                    accessToken,
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(
                                JSONObject object,
                                GraphResponse response) {

                            try {
                                Toast.makeText(getApplicationContext(),""+object.getString("name"),Toast.LENGTH_SHORT).show();
                                System.out.println( object.getString("name"));
                                System.out.println( object.getString("gender"));

                            }
                            catch (JSONException ex)
                            {
                               System.out.println(ex.getMessage());
                            }

                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "name,gender");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            Toast.makeText(getApplicationContext(),"Cancel",Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onError(FacebookException e) {
            Toast.makeText(getApplicationContext(),"ERROR "+e.getMessage(),Toast.LENGTH_SHORT).show();

        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
package com.example.manishnegi.facebook登录;
公共类MainActivity扩展了活动{
登录按钮;
CallbackManager CallbackManager;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
sdkinInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager=callbackManager.Factory.create();
btn=(登录按钮)findViewById(R.id.login_按钮);
btn.registerCallback(callbackManager,new FacebookCallback()){
@凌驾
成功时公共无效(LoginResult LoginResult){
Toast.makeText(getApplicationContext(),“Success”,Toast.LENGTH\u SHORT.show();
AccessToken AccessToken=loginResult.getAccessToken();
GraphRequest请求=GraphRequest.newmereRequest(
accessToken,
新建GraphRequest.GraphJSONObjectCallback(){
@凌驾
公共空间未完成(
JSONObject对象,
GraphResponse(反应){
试一试{
Toast.makeText(getApplicationContext(),“”+object.getString(“name”),Toast.LENGTH\u SHORT.show();
System.out.println(object.getString(“name”);
System.out.println(object.getString(“性别”);
}
捕获(JSONException ex)
{
System.out.println(例如getMessage());
}
}
});
Bundle参数=新Bundle();
parameters.putString(“字段”、“名称、性别”);
请求。设置参数(参数);
request.executeAsync();
}
@凌驾
公开作废{
Toast.makeText(getApplicationContext(),“Cancel”,Toast.LENGTH\u SHORT.show();
}
@凌驾
公共无效onError(FaceBook例外e){
Toast.makeText(getApplicationContext(),“ERROR”+e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}


请帮助我陷入困境

您还可以生成如下哈希键:

private void getHashKey() {
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("RAJAT",
                    "KeyHash: "
                            + Base64.encodeToString(md.digest(),
                                    Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }

}
getHashKey()
mthod调用
onCreate()
并在facebook开发者控制台上使用此哈希键

并检查AndroidManifest文件中的流动条目

<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" />

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

    <meta-data
        android:name="com.facebook.sdk.ApplicationName"
        android:value="@string/facebook_app_name" />

    <provider
        android:name="com.facebook.FacebookContentProvider"
        android:authorities="com.facebook.app.FacebookContentProviderandyourappidfromfacebookconsole"
        android:exported="true" />


我希望这对你有用…

@Brucode请检查你在android清单中的提供者标签中添加了什么应用程序ID或互联网权限……这很好。但它没有显示任何内容,我甚至无法在emulatoridk版本上启动登录屏幕,但我最近从fb的开发者控制台下载了它。所以我猜这是最新的,因为facebook开发者控制台也提供了旧的sdk