在我的Android应用程序中,有两种类型的登录。用户可以使用Facebook或Google+登录。当用户成功登录时,它会显示该特定社交帐户的数据。例如,当用户使用Facebook登录时,它将显示来自Facebook的数据。我已经包含了我的代码:
demo.java
boolean isFacebook;
if (!isFacebook) {
txtName.setText(PrefUtils.getCurrentUser(WelcomeScreenActivity.this).firstname);
txtEmail.setText(PrefUtils.getCurrentUser(WelcomeScreenActivity.this).email);
// fetching facebook's profile picture
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
URL imageURL = null;
try {
imageURL = new URL("https://graph.facebook.com/" + user.facebookID + "/picture?type=small");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
imgProfile.setImageBitmap(bitmap);
}
}.execute();
} else {
isFacebook = false;
SharedPreferences pref = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
String username = pref.getString("PROFILE_USERNAME", "");
String email = pref.getString("PROFILE_EMAIL_GOOGLE", "");
pref.getString("PROFILE_IMAGE_USER", "");
txtName.setText(username);
txtEmail.setText(email);
}
}
在此代码中,当用户使用Facebook登录时,它会显示Google+详细信息。我怎么能纠正这个?
答案 0 :(得分:5)
你的病情错了
一定是这样的
if (!isFacebook) {
// do false logic here you need to check for GOOGLE
}
// do true logic here you need to check for FB
答案 1 :(得分:3)
嗯,你真的与你所描述的相反。如果isFacebook
为false
,您将从Facebook获取数据,这意味着它不是Facebook。
将第一个if语句更改为if (isFacebook)
答案 2 :(得分:3)
改用它(只是犯了一个小错误)
output_nodes = ['subgraph/y', 'subgraph/dropout']
checkpoint = tf.train.latest_checkpoint(input_path)
importer = tf.train.import_meta_graph(checkpoint + '.meta', clear_devices=True)
graph = tf.get_default_graph()
gd = graph.as_graph_def()
with tf.Session() as sess:
importer.restore(sess, checkpoint)
output_graph_def = graph_util.\
convert_variables_to_constants(sess, gd, output_nodes)
tf.train.write_graph(output_graph_def, 'dir', 'file.pb', as_text=False)
但是您提供的此代码似乎并未首先从Google +中收集任何数据
按钮点击可能还有问题
with tf.gfile.GFile(input_path, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
elems = tf.import_graph_def(
graph_def,
input_map=None,
return_elements=output_nodes,
name='imported'
)
如果您将isFacebook初始化为 boolean isFacebook;
if (isFacebook) {
txtName.setText(PrefUtils.getCurrentUser(WelcomeScreenActivity.this).firstname);
txtEmail.setText(PrefUtils.getCurrentUser(WelcomeScreenActivity.this).email);
// fetching facebook's profile picture
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
URL imageURL = null;
try {
imageURL = new URL("https://graph.facebook.com/" + user.facebookID + "/picture?type=small");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
imgProfile.setImageBitmap(bitmap);
}
}.execute();
} else {
//get google + details here
}
}