我刚刚将+1 google添加到了我的按钮,但是在initialize()之后它始终是灰色的,不能执行任何操作:
我的代码如下所示:
public class Stars extends Activity implements ConnectionCallbacks,
OnConnectionFailedListener {
private PlusClient mPlusClient;
PlusOneButton mPlusOneButton;
private static final int PLUS_ONE_REQUEST_CODE = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stars);
// g+1------------------------------------------------------
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities(
"http://schemas.google.com/AddActivity",
"http://schemas.google.com/BuyActivity").build();
mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
// ---------------------------------------------------------
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@Override
protected void onResume() {
mPlusOneButton.initialize(mPlusClient,
"https://developers.google.com/+", PLUS_ONE_REQUEST_CODE);
super.onResume();
}
public void onConnectionFailed(ConnectionResult status) {
// Nothing to do.
}
public void onDisconnected() {
// Nothing to do.
}
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
}
}
如何修复该问题以及我在Google API控制台中注册的代码中的信息在哪里?
最佳答案
尝试在构建器上调用.clearScopes(),而不是根据当前需要对其进行设置以进行登录。在那种情况下,您也不需要connect()或disconnect()。
mPlusClient = new PlusClient(this, this, this)
.clearScopes()
.build();
当前,它与要用于登录的PlusClient设置相关联,但用户尚未登录,因此显示为灰色。