Windows phone 7 如何在windows phone 8中使用photoChooserTask将图像上载到facebook?
我正在开发一个Windows Phone应用程序,在其中我必须将照片发布到facebook。通过使用PhotoChooserTask或CameraChooserTask选择特定的照片 通常情况下,我可以成功发布特定的照片,但我面临的问题是发布选定的照片。我看到了一些类似的链接 所以,如果有人知道这个问题,请帮助我。 提前准备好 编辑Windows phone 7 如何在windows phone 8中使用photoChooserTask将图像上载到facebook?,windows-phone-7,c#-4.0,windows-phone-8,windows-phone,Windows Phone 7,C# 4.0,Windows Phone 8,Windows Phone,我正在开发一个Windows Phone应用程序,在其中我必须将照片发布到facebook。通过使用PhotoChooserTask或CameraChooserTask选择特定的照片 通常情况下,我可以成功发布特定的照片,但我面临的问题是发布选定的照片。我看到了一些类似的链接 所以,如果有人知道这个问题,请帮助我。 提前准备好 编辑 private void PostClicked(object sender, RoutedEventArgs e) { //Client
private void PostClicked(object sender, RoutedEventArgs e)
{
//Client Parameters
var parameters = new Dictionary<string, object>();
//var parameters1 = new Dictionary<>();
parameters["client_id"] = FBApi;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
parameters["ContentType"] = "image/png";
//The scope is what give us the access to the users data, in this case
//we just want to publish on his wall
parameters["scope"] = "publish_stream";
Browser.Visibility = System.Windows.Visibility.Visible;
Browser.Navigate(client.GetLoginUrl(parameters));
}
private void BrowserNavitaged(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//Making sure that the url actually has the access token
if (!client.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
//Checking that the user successfully accepted our app, otherwise just show the error
if (oauthResult.IsSuccess)
{
//Process result
client.AccessToken = oauthResult.AccessToken;
//Hide the browser
Browser.Visibility = System.Windows.Visibility.Collapsed;
PostToWall();
}
else
{
//Process Error
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility = System.Windows.Visibility.Collapsed;
}
}
private void PostToWall()
{
string imageName = "ic_launcher.png";
StreamResourceInfo sri = null;
Uri jpegUri = new Uri(imageName, UriKind.Relative);
sri = Application.GetResourceStream(jpegUri);
try
{
byte[] imageData = new byte[sri.Stream.Length];
sri.Stream.Read(imageData, 0, System.Convert.ToInt32(sri.Stream.Length));
FacebookMediaObject fbUpload = new FacebookMediaObject
{
FileName = imageName,
ContentType = "image/jpg"
};
fbUpload.SetValue(imageData);
string name1 = eventname.Text;
string format = "yyyy-MM-dd";
string message1 = eventmessage.Text;
string date1 = datepicker.ValueString;
DateTime datevalue = DateTime.Parse(date1);
string d = datevalue.ToString(format);
string memoType = "Tribute";
var parameters = new Dictionary<string, object>();
var parameters1 = new Dictionary<string, object>();
parameters["message"] = name1 + "\n" + d + "\n" + memoType + "\n" + message1;
parameters["source"] = fbUpload;
webservice();
client.PostTaskAsync("me/photos", parameters);
}
catch (Exception error)
{
MessageBox.Show(error.ToString());
}
//client.PostTaskAsync("me/photos", parameters1);
}
private void postclick(对象发送方,RoutedEventArgs e)
{
//客户端参数
var参数=新字典();
//var参数s1=新字典();
参数[“客户端id”]=FBApi;
参数[“重定向uri”]=”https://www.facebook.com/connect/login_success.html";
参数[“响应类型”]=“令牌”;
参数[“显示”]=“触摸”;
参数[“ContentType”]=“image/png”;
//在本例中,作用域是我们访问用户数据的基础
//我们只想在他的墙上发表
参数[“范围”]=“发布流”;
Browser.Visibility=System.Windows.Visibility.Visible;
浏览(client.GetLoginUrl(参数));
}
private void BrowserNavitaged(对象发送方,System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//确保url实际具有访问令牌
if(!client.TryParseOAuthCallbackUrl(e.Uri,out oauthResult))
{
返回;
}
//检查用户是否成功接受了我们的应用程序,否则只显示错误
if(oauthResult.IsSuccess)
{
//过程结果
client.AccessToken=oauthResult.AccessToken;
//隐藏浏览器
Browser.Visibility=System.Windows.Visibility.Collapsed;
PostToWall();
}
其他的
{
//过程错误
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility=System.Windows.Visibility.Collapsed;
}
}
私有void PostToWall()
{
字符串imageName=“ic_launcher.png”;
StreamResourceInfo sri=null;
Uri jpegUri=新Uri(imageName,UriKind.Relative);
sri=Application.GetResourceStream(jpegUri);
尝试
{
字节[]图像数据=新字节[sri.Stream.Length];
sri.Stream.Read(imageData,0,System.Convert.ToInt32(sri.Stream.Length));
FacebookMediaObject fbUpload=新建FacebookMediaObject
{
FileName=imageName,
ContentType=“image/jpg”
};
fbUpload.SetValue(图像数据);
字符串名称1=eventname.Text;
字符串格式=“yyyy-MM-dd”;
字符串message1=eventmessage.Text;
string date1=datepicker.ValueString;
DateTime datevalue=DateTime.Parse(date1);
字符串d=datevalue.ToString(格式);
字符串memoType=“贡”;
var参数=新字典();
var参数s1=新字典();
参数[“message”]=name1+“\n”+d+“\n”+memoType+“\n”+message1;
参数[“源”]=fbUpload;
webservice();
PostTaskAsync(“我/照片”,参数);
}
捕获(异常错误)
{
Show(error.ToString());
}
//客户端.PostTaskAsync(“我/照片”,参数1);
}
点击一个按钮,我会调用PostClicked类,它会直接进入facebook主页,并询问登录信息。就像我正在做的那样。
请查看您可以通过两种方法来实现: 1) 通过使用mediasharetask,它将向你显示你手机同步到的所有共享帐户,如facebook、gmail、linkdin、twitter等:它可以像这样使用
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = path;
shareMediaTask.Show();
2) 通过使用facebook sdk。您可以从nuget manager获得该软件包,然后您可以使用它在facebook上进行共享
我希望这可能会对你有所帮助。现在我可以使用photochoosertask或cameratask成功地将照片分享到facebook。 我正在分享我的经验,这样如果有人面临同样的问题,就可以使用它
private void photoChooserTask_Completed(object sender, PhotoResult e)
{
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
SaveImageToIsolatedStorage(image, tempJPEG);
this.image.Source = image;
}
public void SaveImageToIsolatedStorage(BitmapImage image, string fileName)
{
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isolatedStorage.FileExists(fileName))
isolatedStorage.DeleteFile(fileName);
var fileStream = isolatedStorage.CreateFile(fileName);
if (image != null)
{
var wb = new WriteableBitmap(image);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
}
fileStream.Close();
}
}
使用此选项,您可以将所选图像保存到IsolatedStorage。
然后在将照片发布到facebook时,您必须从IsolatedStorage中选择图像
private void PostClicked(object sender, RoutedEventArgs e)
{
//Client Parameters
var parameters = new Dictionary<string, object>();
parameters["client_id"] = FBApi;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
//The scope is what give us the access to the users data, in this case
//we just want to publish on his wall
parameters["scope"] = "publish_stream";
Browser.Visibility = System.Windows.Visibility.Visible;
Browser.Navigate(client.GetLoginUrl(parameters));
}
private void BrowserNavitaged(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//Making sure that the url actually has the access token
if (!client.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
//Checking that the user successfully accepted our app, otherwise just show the error
if (oauthResult.IsSuccess)
{
//Process result
client.AccessToken = oauthResult.AccessToken;
//Hide the browser
Browser.Visibility = System.Windows.Visibility.Collapsed;
PostToWall();
}
else
{
//Process Error
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility = System.Windows.Visibility.Collapsed;
}
}
private void PostToWall()
{
try
{
byte[] data;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read))
{
data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
}
}
//MemoryStream ms = new MemoryStream(data);
//BitmapImage bi = new BitmapImage();
//// Set bitmap source to memory stream
//bi.SetSource(ms);
//this.imageTribute.Source = bi;
FacebookMediaObject fbUpload = new FacebookMediaObject
{
FileName = tempJPEG,
ContentType = "image/jpg"
};
fbUpload.SetValue(data);
string name1 = eventname.Text;
string format = "yyyy-MM-dd";
string message1 = eventmessage.Text;
string date1 = datepicker.ValueString;
DateTime datevalue = DateTime.Parse(date1);
string d = datevalue.ToString(format);
string memoType = "Notice";
var parameters = new Dictionary<string, object>();
var parameters1 = new Dictionary<string, object>();
parameters["message"] = name1;
parameters["source"] = fbUpload;
webservice();
client.PostTaskAsync("me/photos", parameters);
}
catch (Exception error)
{
MessageBox.Show(error.ToString());
}
}
private void postclick(对象发送方,RoutedEventArgs e)
{
//客户端参数
var参数=新字典();
参数[“客户端id”]=FBApi;
参数[“重定向uri”]=”https://www.facebook.com/connect/login_success.html";
参数[“响应类型”]=“令牌”;
参数[“显示”]=“触摸”;
//在本例中,作用域是我们访问用户数据的基础
//我们只想在他的墙上发表
参数[“范围”]=“发布流”;
Browser.Visibility=System.Windows.Visibility.Visible;
浏览(client.GetLoginUrl(参数));
}
private void BrowserNavitaged(对象发送方,System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//确保url实际具有访问令牌
if(!client.TryParseOAuthCallbackUrl(e.Uri,out oauthResult))
{
返回;
}
//检查用户是否成功接受了我们的应用程序,否则只显示错误
if(oauthResult.IsSuccess)
{
//过程结果
client.AccessToken=oauthResult.AccessToken;
//隐藏浏览器
Browser.Visibility=System.Windows.Visibility.Collapsed;
PostToWall();
}
其他的
{
//过程错误
MessageBox.Show(oauthResult.ErrorDescription);
浏览器.可见性