如何从我的服务器获取令牌?我进行了简单的过程,只需让令牌出现在我的服务器上,但现在我不知道如何将其下拉并在我的Android应用程序中使用它。这是Braintree建议的方法,当我复制并粘贴它时,它会出现错误。我设法通过他们,但我必须实施一些我认为不对的方法。
我需要做的就是获取客户端令牌并在我的应用中用作变量。有人请帮忙。附:我是Android开发人员的新手。
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.loopj.android.http.*;
import com.braintreepayments.api.dropin.BraintreePaymentActivity;
import org.apache.http.Header;
public class MainActivity extends ActionBarActivity {
private int REQUEST_CODE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
AsyncHttpClient client = new AsyncHttpClient();
public void fetchClientToken() {
client.get("http://clomes.com/clomes/braintree/customer/gettoken", new TextHttpResponseHandler() {
public String clientToken;
@Override
public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
}
@Override
public void onSuccess(int i, Header[] headers, String clientToken) {
this.clientToken = clientToken;
}
});
}
@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);
}
}