我试图允许用户使用FlickrNet库/ API从Asp.net应用程序上传视频到Flickr.我从Flickr获得了API密钥和API秘密.另外,我正在使用FlickrNet库中的AuthGetFrob方法检索authToken.
我的使用陈述如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlickrNet;
Run Code Online (Sandbox Code Playgroud)
我创建了两种方法来完成这项任务.
获取并返回AuthToken的一个
private string GetAuthenticateToken()
{
Flickr flickr = new Flickr(FLICKR_API_KEY, FLICKR_API_SECRET);
string frob = flickr.AuthGetFrob();
return flickr.AuthCalcUrl(frob, AuthLevel.Write);
}
Run Code Online (Sandbox Code Playgroud)
一个使用AuthToken上传文件
public void UploadFile(string fileName, string title, string description)
{
try
{
string authToken = GetAuthenticateToken();
Flickr flickr = new Flickr(FLICKR_API_KEY, FLICKR_API_SECRET, authToken);
string photoId = flickr.UploadPicture(fileName, title, description, "", true, false, false);
}
catch (Exception ex)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我调用'UploadPicture'时,会抛出以下异常.'无效的身份验证令牌(98)'.
AuthRequest Http请求的内容如下所示.
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) 似乎这应该是一个常见的问题,我希望通过快速谷歌搜索找到答案,但唉,我似乎无法找到答案.
我正在使用C#中的NUnit编写单元测试,以获取依赖于第三方库的方法,Newtonsoft.Json是特定的.
当我尝试从我的单元测试中调用该方法时,我会收到所有共同点
无法加载文件或程序集"Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed"或其中一个依赖项.定位程序集的清单定义与程序集引用"异常不匹配.
单元测试和应用程序都使用完全相同的newtonsoft库,并且dll设置为在两个项目中复制本地.
似乎我错过了一些非常明显的东西,但我似乎无法克服这个问题.
所以我主要是C#和Java开发人员,但我想这个问题可能适用于使用StringBuilder或其衍生物的任何编程语言.
好的,所以或多或少的常识,连接即使少量的字符串也可能是主要的性能杀手(尽管这是有争议的).我的问题是,是否有人知道在字符串生成器中使用字符串生成器的性能影响.为了澄清我的意思,让我加入一些虚拟代码来帮助说明我的观点.
此外,我意识到通过调用StringBuilder的多个实例自然会有性能损失但我不相信我会调用它足以导致任何真正的性能问题.(这个假设也可能是错误的,任何意见也会有所帮助)
public string StringToGet()
{
StringBuilder sb = new StringBuilder("Some Text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append(MethodThatCreatesAnotherString());
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append("more text to add");
sb.append(MethodThatCreatesAnotherString());
sb.append("more text to add");
sb.append("more text to …Run Code Online (Sandbox Code Playgroud) 我有以下要求。用户需要能够在我的应用中安排定期提醒,该提醒将在每天的确切时间触发推送通知。
这是我希望最终不要提交的那些问题之一,因为在编写它时建议您提出类似的问题。但是,几个团队成员花了很多时间来查看Android Developer Docs和Stackoverflow,我们似乎离答案还很近,所以我们到了。
如果我创建了一个提醒并将其设置为在未来5分钟触发通知,则该通知会正常触发。
我怀疑这可能是由于Android P中引入的节电,唤醒锁等更改引起的问题,因为在将目标SDK更新到28之前我们没有这个问题。唯一的问题,但我可以在运行Android P的Pixel和Pixel 3 XL上一贯重现该问题。
例如,当用户将提醒设置为半夜的某个时间(大概是在用户处于睡眠状态,因此将有几个小时没有使用电话)时,便会发生通知未触发的示例。这些提醒从未触发过。
我目前正在尝试使用“警报管理器”来完成此操作。
该问题似乎类似于另一个问题,该问题使用了警报管理器的setRepeating方法,但我们发现该方法不起作用。相反,我们使用警报管理器的setExactAndAllowWhileIdle方法。我们还使用Alarm Managers setAlarmClock方法尝试了相同的实现,根据Android文档,该方法“即使系统处于低功率空闲(也称为打ze)模式,也将被允许触发”,但这也没有成功。
我怀疑这不起作用的原因是因为在电话处于打ze模式时setExactAndAllowWhileIdle不会触发,类似于此问题中表达的问题。此问题建议使用Firebase JobDispatcher,但由于这是内部通知,因此无论是否具有网络连接,我都需要触发该通知,这似乎消除了Firebase JobDispatcher的选择。这个问题还表明,一旦手机退出打ze模式,用户会收到通知,但我们从未收到通知,他们似乎因为缺少更好的条件而迷路了。
我已将唤醒锁定权限添加到我的AndroidManifest.xml中:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Run Code Online (Sandbox Code Playgroud)
这是我的接收者在AndroidManifest.xml中的注册方式
<receiver android:name="com.myapp.receiver.AlarmReceiver">
</receiver>
Run Code Online (Sandbox Code Playgroud)
这是我当前的实现:
待处理通知的意图
Intent i = new Intent(context, ScheduleAllReceiver.class);
PendingIntent scheduleAllPendingIntent = PendingIntent.getBroadcast(context, SCHEDULER_DAILY_ALL, i, PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)
我随后将方法称为“ createAlarm”,如下所示
createAlarm(context, scheduleAllPendingIntent, calendar.getTimeInMillis());
Run Code Online (Sandbox Code Playgroud)
创建警报
public static void createAlarm(Context context, PendingIntent pendingIntent, long timeinMilli) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if(alarmManager != null) {
if (Build.VERSION.SDK_INT >= 23) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeinMilli, …Run Code Online (Sandbox Code Playgroud) notifications android alarmmanager android-doze android-9.0-pie
我似乎无法将我的ASP.net应用程序成功发布到我的YouTube帐户,但无论我做什么,我都会收到400 Bad Request错误.我使用YouTube文档创建代码并获取开发密钥.此外,我没有收到和身份验证错误,所以我相信我的参数是正确的.尽管进行了大量的搜索,我仍然无法找到我的任务的确切答案,所以我只能假设我错误地使用了API或省略了一些关键的东西.
我的使用指令如下
using System;
using Google.GData.Client;
using Google.GData.YouTube;
using Google.GData.Extensions;
using Google.GData.Extensions.MediaRss;
using Google.YouTube;
我的调用API的代码就在这里
YouTubeRequestSettings settings = new YouTubeRequestSettings("k2ps",
YOU_TUBE_DEVELOPER_KEY, YOU_TUBE_USER_NAME, YOU_TUBE_PASSWORD);
YouTubeRequest request = new YouTubeRequest(settings);
Video video = new Video();
video.Title = title;
video.Tags.Add(new MediaCategory(sport, YouTubeNameTable.CategorySchema));
video.Keywords = keyword;
video.Description = "K2ps"; //todo replace this with the preview text
video.YouTubeEntry.Private = false;
video.YouTubeEntry.MediaSource = new MediaFileSource(videoPath, "video/x-flv");
Video createdVideo = request.Upload(video);
Run Code Online (Sandbox Code Playgroud)
我正在抛出HTTP 400 Bad请求异常.我用fiddler来获得下面的原始响应.
执行请求失败: Google.GData.Client上的http://uploads.gdata.youtube.com/feeds/api/users/default/uploads
HTTP/1.1 400 Bad Request
Server: Upload Server Built …Run Code Online (Sandbox Code Playgroud) 所以我需要使用我项目中包含的font.otf文件将.otf字体文件添加到c#中的PrivateFontCollection.当文件在本地加载时,我在部署到服务器时收到以下异常.
[例外:无法在路径中找到字体:D:\ Inetpub\MyApplication\Content\Fonts\ProximaNovaAlt-Black.otf例外是:System.IO.FileNotFoundException:找不到文件.在System.Drawing.Text.PrivateFontCollection.AddFontFile(String filename)
但是,当我查看Web服务器并导航到该确切目录时,该文件就在那里并且不是只读的.
字体文件在我的项目中的位置如下/Content/Fonts/ProximaNovaAlt-Black.otf
此外,ProximaNovaAlt-Black.otf文件的属性如下所示.

最后,这是抛出错误的代码
public Font GetFont(float fontSize)
{
string path = HttpContext.Current.Server.MapPath(AppDomain.CurrentDomain.BaseDirectory + @"Content\Fonts\ProximaNovaAlt-Black.otf");
try
{
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile(path);
return new Font(privateFontCollection.Families[0], fontSize);
}
catch (Exception ex)
{
throw new Exception("Could not find font at path: " + path + " The exception is: " + ex.ToString());
}
}
Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net ×3
.net ×1
alarmmanager ×1
android ×1
android-doze ×1
flickr ×1
fonts ×1
java ×1
json.net ×1
nunit ×1
string ×1
unit-testing ×1
youtube ×1
youtube-api ×1