简体   繁体   English

PhotobucketNet照片上传

[英]PhotobucketNet photo upload

I have a problem with PhotobucketNet user login(I need user to login so I can upload a picture from HDD to his Photobucket account). 我的PhotobucketNet用户登录有问题(我需要用户登录,以便可以将HDD中的图片上传到他的Photobucket帐户)。

Photobucket photobucket = new Photobucket("myapikey", "myapisecret");
photobucket.LaunchUserLogin();
// the problem happens here
photobucket.RequestUserToken();

If I call RequestUserToken() it will happen immediately, so I'll get a crash cause user didn't logged in, and there is no event that's been raised after user logs in. Is there some variable(bool or something else) that I can check to see if user logged in - maybe to put it in a loop with timer? 如果我调用RequestUserToken(),它将立即发生,因此会导致崩溃,原因是用户未登录,并且用户登录后未引发任何事件。是否存在一些变量(布尔值或其他变量)我可以检查用户是否登录-也许将其与计时器循环? Also is their a way to know if user canceled logging in? 他们还能知道用户是否取消登录吗? I know that timer isn't a good solution, so if anyone has anything better as an idea, I'm open for any suggestions... 我知道计时器不是一个好的解决方案,所以如果有人有更好的想法,我愿意征求任何建议...

I've encountered the same problem today and i found your post while i was searching for solutions. 我今天也遇到了同样的问题,我在寻找解决方案时找到了您的帖子。 Here is how i managed to solve the problem: 这是我设法解决问题的方法:

Firstly, i got the "user login url" and passed it to a form with a web browser control, called "Login". 首先,我获得了“用户登录URL”,并将其传递给带有Web浏览器控件的表单,称为“登录”。

Service=new Photobucket ("mykey", "mysecret");
string u=Service.GenerateUserLoginUrl ();
Login l=new Login (u);
l.Show ();

Next, I got the url from this page, 接下来,我从该页面获得了网址,

在此处输入图片说明

which is the page after the login. 这是登录后的页面。 If the web browser's url is that page, i asked the photobucket class (in my case Program.Service), to request the token. 如果Web浏览器的URL是该页面,则我要求photobucket类(在我的情况下为Program.Service)请求令牌。

The code from the Login form is something like this: 登录表单中的代码是这样的:

public Login (string url)
{
    InitializeComponent ();
    webBrowser1.Navigate (url);
    webBrowser1.DocumentCompleted+=delegate
    {
    if (webBrowser1.Url.ToString ()=="http://photobucket.com/apilogin/done")
       {
             PhotobucketNet.UserToken t=Program.Service.RequestUserToken ();
             //save the token
       }
    }
}

Now you just save the token and use it. 现在,您只需保存令牌并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM