gpt4 book ai didi

android - 通过在不同 Activity 中使用 SocialAuth 更新 Facebook 上的状态

转载 作者:行者123 更新时间:2023-11-30 02:51:25 25 4
gpt4 key购买 nike

我正在尝试使用 Socialauth 库更新状态,但我想通过 Activity 更新状态而不是对话框。它用对话框完成,但我想用 Activity 来完成。

我有两个 Activity - 一个 Activity 包含两个按钮,一个是登录按钮,另一个是下一个按钮,当我点击 login 然后它成功验证并点击下一步我进入下一个包含的 Activity edittext按钮。在编辑文本中,我键入我的消息,然后单击按钮,我调用 Social authupdateStatus() 方法。但是我收到了服务器的响应,即错误 403..

这是我的代码

public class Social_MainActivity extends Activity {

public static SocialAuthAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_social__main);
Button login=(Button) findViewById(R.id.buttonLogin);

adapter = new SocialAuthAdapter(new ResponseListener());
login.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
adapter.authorize(Social_MainActivity.this,Provider.FACEBOOK);

}
});



next.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Intent i=new Intent(Social_MainActivity.this,ProviderActivity.class);
startActivity(i);
}
});


}



class ResponseListener implements DialogListener
{




@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub

Toast.makeText(Social_MainActivity.this, "You are login", 1000).show();*/
}

@Override
public void onError(SocialAuthError e) {
// TODO Auto-generated method stub
Log.d("ShareBar", e.getMessage());


}

@Override
public void onCancel() {
// TODO Auto-generated method stub
Log.d("ShareBar", "Authentication Cancelled");

}

@Override
public void onBack() {
// TODO Auto-generated method stub

}


}
}

提供 Activity :

      public class ProviderActivity extends Activity{

SocialAuthAdapter adapter;
EditText ed;
Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.provider_activity);
ed=(EditText) findViewById(R.id.shareText);
b=(Button) findViewById(R.id.updatebutton);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

adapter = Social_MainActivity.adapter;
adapter.updateStatus(ed.getText.toString(),new MessageListener(),true);
Toast.makeText(ProviderActivity.this,"updated", 1000).show();

}
});
}
private final class MessageListener implements SocialAuthListener<Integer> {




@Override
public void onExecute(String provider, Integer t) {
// TODO Auto-generated method stub
Integer status = t;
if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)
Toast.makeText(Social_MainActivity.this, "Message posted",Toast.LENGTH_LONG).show();
else
Toast.makeText(Social_MainActivity.this, "Message not posted",Toast.LENGTH_LONG).show();
Log.e("Execute", "I am onExecute");

}

@Override
public void onError(SocialAuthError e) {
// TODO Auto-generated method stub
Log.e("Error", "I am onExecute Error");

}
}

最佳答案

已经解决了。这是我的代码。我正在使用 3 个类。如果有人可以建议我更好的方法,那么请。此代码在 Facebook 和推特上更新。

public class Social_MainActivity extends Activity {


static MySocialAuthAdapter myadap;

Context con;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_social__main);
con=this;


Button share=(Button) findViewById(R.id.button1);
Button twiitter=(Button) findViewById(R.id.button_twitterLogin);
Button login=(Button) findViewById(R.id.buttonLogin);

myadap=new MySocialAuthAdapter();// MySocialAuthAdapter is user defined class

login.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myadap.MyAuthorize(con, Provider.FACEBOOK);

}
});
twiitter.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myadap.MyAuthorize(con, Provider.TWITTER);

}
});
share.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Intent i=new Intent(Social_MainActivity.this,ProviderActivity.class);
startActivity(i);
}
});
}


}

MySocialAuthAdapter 类:-

    public class MySocialAuthAdapter  {

public static SocialAuthAdapter adapter;
public MySocialAuthAdapter()
{
adapter = new SocialAuthAdapter(new ResponseListener());


}
public void MyAuthorize(Context context,SocialAuthAdapter.Provider provider)
{

adapter.authorize(context, provider);

}
public void MyUpdateStatus(String msg)
{
adapter.updateStatus(msg, new MessageListener(), true);
Log.e("Message","Your message hv been updated");

}
class ResponseListener implements DialogListener
{

@Override
public void onComplete(Bundle values) {

}

@Override
public void onError(SocialAuthError e) {
// TODO Auto-generated method stub
Log.d("ShareBar", e.getMessage());


}

@Override
public void onCancel() {
// TODO Auto-generated method stub
Log.d("ShareBar", "Authentication Cancelled");

}

@Override
public void onBack() {
// TODO Auto-generated method stub

}


}

private final class MessageListener implements SocialAuthListener<Integer> {
@Override
public void onExecute(String provider, Integer t) {
// TODO Auto-generated method stub
Integer status = t;
if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)

Log.e("Execute", "I am onExecute");

}

@Override
public void onError(SocialAuthError e) {
// TODO Auto-generated method stub
Log.e("Error", "I am onExecute Error");

}
}
}
}

ProviderActivity 类:-

 public class ProviderActivity extends Activity{
MyApplication myApp;
MySocialAuthAdapter myadapter;
EditText ed;
Button b;
String msg;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.provider_activity);
ed=(EditText) findViewById(R.id.shareText);
b=(Button) findViewById(R.id.updatebutton);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Social_MainActivity.myadap.MyUpdateStatus( ed.getText().toString());

}
});


}

}

关于android - 通过在不同 Activity 中使用 SocialAuth 更新 Facebook 上的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24096081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com