在apisauce中使用addAsyncRequestTransform获取令牌的正确方法是什么?

时间:2019-08-26 20:45:31

标签: javascript es6-promise

在向我自己的服务发出请求之前,我需要调用另一个API来更新令牌。从Apisauce文档中:

takeWebshot(firstLine, secondLine, previewID, productPlate) .then(function(){console.log("promise works!")})
  

例如,如果您需要从存储中获取API密钥,那么这很好。   https://www.npmjs.com/package/apisauce

我的尝试是这样的:

public class Score extends Activity {
public Button plus;
public Button minus;
public TextView scoretext;
public int value;
public static final String mypreference = "mypref";
SharedPreferences sharedpreferences;
public void save(View v){
    SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putInt("inte", value); // Storing integer
    editor.apply(); // commit changes
}
public void restore(View v){
    this.sharedpreferences = this.getSharedPreferences("myPerf",
            Context.MODE_PRIVATE);

    if (this.sharedpreferences.contains("inte")) {
        okeh.setText(this.sharedpreferences.getInt("inte",value));
    }

}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_score);
    plus = this.findViewById(R.id.plus);
    scoretext=this.findViewById(R.id.scoretext);
    minus=this.findViewById(R.id.minus);

    plus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            value++;
            String scorestring=String.valueOf(value);
            scoretext.setText(scorestring);
        }
    });
    minus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            value--;
            String scorestring=String.valueOf(value);
            scoretext.setText(scorestring);
        }
    });
    sharedpreferences = this.getSharedPreferences(mypreference,
            Context.MODE_PRIVATE);
    if (sharedpreferences.contains("inte")) {
        okeh.setText(sharedpreferences.getInt("inte", value));
    }
}
}

我确实收到了有效的令牌,但请求已发送但没有令牌。显然这里有些我想念或不明白的东西。

0 个答案:

没有答案